Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/engines/common


Modified Files:
        evas_font_draw.c evas_font_load.c evas_image_load.c 
        evas_image_main.c evas_image_save.c 


Log Message:


use stringshare. saves a few hundred allocs... if we start doing lots of text
:)

===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_draw.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- evas_font_draw.c    16 Nov 2005 13:17:27 -0000      1.17
+++ evas_font_draw.c    28 Nov 2005 15:18:00 -0000      1.18
@@ -227,54 +227,50 @@
                                 int bi, bj;
                                 const DATA8 bitrepl[2] = {0x0, 0xff};
                                 
-                                tmpbuf = malloc(w);
-                                if (tmpbuf)
+                                tmpbuf = alloca(w);
+                                for (i = 0; i < h; i++)
                                   {
-                                     for (i = 0; i < h; i++)
+                                     int dx, dy;
+                                     int in_x, in_w, end;
+                                     
+                                     in_x = 0;
+                                     in_w = 0;
+                                     dx = chr_x;
+                                     dy = y - (chr_y - i - y);
+                                     tp = tmpbuf;
+                                     dp = data + (i * 
fg->glyph_out->bitmap.pitch);
+                                     for (bi = 0; bi < w; bi += 8)
                                        {
-                                          int dx, dy;
-                                          int in_x, in_w, end;
-                                          
-                                          in_x = 0;
-                                          in_w = 0;
-                                          dx = chr_x;
-                                          dy = y - (chr_y - i - y);
-                                          tp = tmpbuf;
-                                          dp = data + (i * 
fg->glyph_out->bitmap.pitch);
-                                          for (bi = 0; bi < w; bi += 8)
+                                          bits = *dp;
+                                          if ((w - bi) < 8) end = w - bi;
+                                          else end = 8;
+                                          for (bj = 0; bj < end; bj++)
                                             {
-                                               bits = *dp;
-                                               if ((w - bi) < 8) end = w - bi;
-                                               else end = 8;
-                                               for (bj = 0; bj < end; bj++)
-                                                 {
-                                                    *tp = bitrepl[(bits >> (7 
- bj)) & 0x1];
-                                                    tp++;
-                                                 }
-                                               dp++;
+                                               *tp = bitrepl[(bits >> (7 - 
bj)) & 0x1];
+                                               tp++;
                                             }
-                                          if ((dx < (ext_x + ext_w)) &&
-                                              (dy >= (ext_y)) &&
-                                              (dy < (ext_y + ext_h)))
+                                          dp++;
+                                       }
+                                     if ((dx < (ext_x + ext_w)) &&
+                                         (dy >= (ext_y)) &&
+                                         (dy < (ext_y + ext_h)))
+                                       {
+                                          if (dx + w > (ext_x + ext_w))
+                                            in_w += (dx + w) - (ext_x + ext_w);
+                                          if (dx < ext_x)
+                                            {
+                                               in_w += ext_x - dx;
+                                               in_x = ext_x - dx;
+                                               dx = ext_x;
+                                            }
+                                          if (in_w < w)
                                             {
-                                               if (dx + w > (ext_x + ext_w))
-                                                 in_w += (dx + w) - (ext_x + 
ext_w);
-                                               if (dx < ext_x)
-                                                 {
-                                                    in_w += ext_x - dx;
-                                                    in_x = ext_x - dx;
-                                                    dx = ext_x;
-                                                 }
-                                               if (in_w < w)
-                                                 {
-                                                    func(tmpbuf + in_x,
-                                                         im + (dy * im_w) + dx,
-                                                         w - in_w,
-                                                         dc->col.col);
-                                                 }
+                                               func(tmpbuf + in_x,
+                                                    im + (dy * im_w) + dx,
+                                                    w - in_w,
+                                                    dc->col.col);
                                             }
                                        }
-                                     free(tmpbuf);
                                   }
                              }
                         }
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_load.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -3 -r1.24 -r1.25
--- evas_font_load.c    26 Nov 2005 05:24:25 -0000      1.24
+++ evas_font_load.c    28 Nov 2005 15:18:00 -0000      1.25
@@ -13,22 +13,21 @@
 RGBA_Font_Source *
 evas_common_font_source_memory_load(const char *name, const void *data, int 
data_size)
 {
-   int error, len;
+   int error;
    RGBA_Font_Source *fs;
 
-   len = strlen(name);
-   fs = calloc(1, sizeof(RGBA_Font_Source) + len + 1 + data_size);
+   fs = calloc(1, sizeof(RGBA_Font_Source) + data_size);
    if (!fs) return NULL;
-   fs->name = ((char *)fs) + sizeof(RGBA_Font_Source);
-   strcpy(fs->name, name);
+   fs->name = evas_stringshare_add(name);
    fs->file = NULL;
-   fs->data = fs->name + len + 1;
+   fs->data = ((unsigned char *)fs) + sizeof(RGBA_Font_Source);
    fs->current_size = 0;
    memcpy(fs->data, data, data_size);
    fs->data_size = data_size;
    error = FT_New_Memory_Face(evas_ft_lib, fs->data, fs->data_size, 0, 
&(fs->ft.face));
    if (error)
      {
+       evas_stringshare_del(fs->name);
        free(fs);
        return NULL;
      }
@@ -46,14 +45,12 @@
 RGBA_Font_Source *
 evas_common_font_source_load(const char *name)
 {
-   int error, len;
+   int error;
    RGBA_Font_Source *fs;
 
-   len = strlen(name);
-   fs = calloc(1, sizeof(RGBA_Font_Source) + len + 1);
+   fs = calloc(1, sizeof(RGBA_Font_Source));
    if (!fs) return NULL;
-   fs->name = ((char *)fs) + sizeof(RGBA_Font_Source);
-   strcpy(fs->name, name);
+   fs->name = evas_stringshare_add(name);
    fs->file = fs->name;
    fs->data = NULL;
    fs->data_size = 0;
@@ -61,6 +58,7 @@
    error = FT_New_Face(evas_ft_lib, fs->file, 0, &(fs->ft.face));
    if (error)
      {
+       evas_stringshare_del(fs->name);
        free(fs);
        return NULL;
      }
@@ -126,6 +124,7 @@
 
    fonts_src = evas_object_list_remove(fonts_src, fs);
    FT_Done_Face(fs->ft.face);
+   if (fs->name) evas_stringshare_del(fs->name);
    free(fs);
 }
 
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_image_load.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- evas_image_load.c   31 Aug 2005 17:33:32 -0000      1.21
+++ evas_image_load.c   28 Nov 2005 15:18:00 -0000      1.22
@@ -200,15 +200,8 @@
        fclose(f);
        return -1;
      }
-   lines = (unsigned char **) malloc(h * sizeof(unsigned char *));
+   lines = (unsigned char **) alloca(h * sizeof(unsigned char *));
 
-   if (!lines)
-     {
-       evas_common_image_surface_free(im->image);
-       png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
-       fclose(f);
-       return -1;
-     }
    if (hasg)
      {
        png_set_gray_to_rgb(png_ptr);
@@ -218,7 +211,6 @@
    for (i = 0; i < h; i++)
      lines[i] = ((unsigned char *)(im->image->data)) + (i * w * 
sizeof(DATA32));
    png_read_image(png_ptr, lines);
-   free(lines);
    png_read_end(png_ptr, info_ptr);
    png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
    fclose(f);
@@ -351,16 +343,10 @@
        jpeg_destroy_decompress(&cinfo);
        return -1;
      }
-   data = malloc(w * 16 * 3);
-   if (!data)
-     {
-       jpeg_destroy_decompress(&cinfo);
-       return -1;
-     }
+   data = alloca(w * 16 * 3);
    evas_common_image_surface_alloc(im->image);
    if (!im->image->data)
      {
-       free(data);
        jpeg_destroy_decompress(&cinfo);
        return -1;
      }
@@ -411,7 +397,6 @@
               }
          }
      }
-   free(data);
 /* end data decoding */
    jpeg_finish_decompress(&cinfo);
    jpeg_destroy_decompress(&cinfo);
@@ -457,15 +442,9 @@
        jpeg_destroy_decompress(&cinfo);
        return -1;
      }
-   data = malloc(w * 16 * 3);
-   if (!data)
-     {
-       jpeg_destroy_decompress(&cinfo);
-       return -1;
-     }
+   data = alloca(w * 16 * 3);
    if (!im->image->data)
      {
-       free(data);
        jpeg_destroy_decompress(&cinfo);
        return -1;
      }
@@ -518,7 +497,6 @@
               }
          }
      }
-   free(data);
 /* end data decoding */
    jpeg_finish_decompress(&cinfo);
    jpeg_destroy_decompress(&cinfo);
@@ -958,15 +936,14 @@
 //   im->timestamp = mod_time;
    if (file)
      {
-       im->info.file = strdup(file);
+       im->info.file = evas_stringshare_add(file);
 //     im->info.real_file = real_file;
      }
    else
      {
 //     if (real_file) free(real_file);
      }
-   if (key)
-     im->info.key = strdup(key);
+   if (key) im->info.key = evas_stringshare_add(key);
    evas_common_image_ref(im);
    return im;
 }
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_image_main.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- evas_image_main.c   9 Sep 2005 13:45:07 -0000       1.20
+++ evas_image_main.c   28 Nov 2005 15:18:00 -0000      1.21
@@ -227,10 +227,10 @@
 evas_common_image_free(RGBA_Image *im)
 {
    if (im->image) evas_common_image_surface_free(im->image);
-   if (im->info.file) free(im->info.file);
-   if (im->info.real_file) free(im->info.real_file);
-   if (im->info.key) free(im->info.key);
-   if (im->info.comment) free(im->info.comment);
+   if (im->info.file) evas_stringshare_del(im->info.file);
+//   if (im->info.real_file) evas_stringshare_del(im->info.real_file);
+   if (im->info.key) evas_stringshare_del(im->info.key);
+   if (im->info.comment) evas_stringshare_del(im->info.comment);
    free(im);
 }
 
@@ -335,8 +335,9 @@
    if (im->flags & RGBA_IMAGE_INDEXED) return;
    if ((!im->info.file) && (!im->info.key)) return;
    l1 = 0;
-   if (im->info.real_file) l1 = strlen(im->info.real_file);
-   else if (im->info.file) l1 = strlen(im->info.file);
+//   if (im->info.real_file) l1 = strlen(im->info.real_file);
+//   else
+     if (im->info.file) l1 = strlen(im->info.file);
    l2 = 0;
    if (im->info.key) l2 = strlen(im->info.key);
    snprintf(buf, sizeof(buf), "%llx", im->timestamp);
@@ -344,8 +345,9 @@
    key = malloc(l1 + 5 + l2 + 5 + l3 +1);
    if (!key) return;
    key[0] = 0;
-   if (im->info.real_file) strcpy(key, im->info.real_file);
-   else if (im->info.file) strcpy(key, im->info.file);
+//   if (im->info.real_file) strcpy(key, im->info.real_file);
+//   else
+     if (im->info.file) strcpy(key, im->info.file);
    strcat(key, "//://");
    if (im->info.key) strcat(key, im->info.key);
    strcat(key, "//://");
@@ -365,8 +367,9 @@
    if (!(im->flags & RGBA_IMAGE_INDEXED)) return;
    if ((!im->info.file) && (!im->info.key)) return;
    l1 = 0;
-   if (im->info.real_file) l1 = strlen(im->info.real_file);
-   else if (im->info.file) l1 = strlen(im->info.file);
+//   if (im->info.real_file) l1 = strlen(im->info.real_file);
+//   else
+     if (im->info.file) l1 = strlen(im->info.file);
    l2 = 0;
    if (im->info.key) l2 = strlen(im->info.key);
    snprintf(buf, sizeof(buf), "%llx", im->timestamp);
@@ -374,8 +377,9 @@
    key = malloc(l1 + 5 + l2 + 5 + l3 +1);
    if (!key) return;
    key[0] = 0;
-   if (im->info.real_file) strcpy(key, im->info.real_file);
-   else if (im->info.file) strcpy(key, im->info.file);
+//   if (im->info.real_file) strcpy(key, im->info.real_file);
+//   else 
+     if (im->info.file) strcpy(key, im->info.file);
    strcat(key, "//://");
    if (im->info.key) strcat(key, im->info.key);
    strcat(key, "//://");
@@ -423,7 +427,7 @@
    free(str);
    if (im)
      {
-       if (real_filename) free(real_filename);
+//     if (real_filename) free(real_filename);
        return im;
      }
 
@@ -433,6 +437,7 @@
 
        im = (RGBA_Image *)l;
        ok = 0;
+/*     
        if ((real_filename) && (im->info.real_file))
          {
              if ((im->info.real_file) &&
@@ -441,6 +446,7 @@
               ok++;
          }
        else
+ */
          {
             if ((filename) && (im->info.file) &&
                 (!strcmp(filename, im->info.file)))
@@ -457,11 +463,11 @@
          ok++;
        if (ok >= 3)
          {
-            if (real_filename) free(real_filename);
+//          if (real_filename) free(real_filename);
             return im;
          }
      }
-   if (real_filename) free(real_filename);
+//   if (real_filename) free(real_filename);
    return NULL;
 }
 
@@ -472,7 +478,7 @@
 
    ram += sizeof(struct _RGBA_Image);
    if (im->info.file) ram += strlen(im->info.file);
-   if (im->info.real_file) ram += strlen(im->info.real_file);
+//   if (im->info.real_file) ram += strlen(im->info.real_file);
    if (im->info.key) ram += strlen(im->info.key);
    if (im->info.comment) ram += strlen(im->info.comment);
    if ((im->image) && (im->image->data) && (!im->image->no_free))
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_image_save.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- evas_image_save.c   11 Nov 2005 07:56:10 -0000      1.1
+++ evas_image_save.c   28 Nov 2005 15:18:00 -0000      1.2
@@ -94,14 +94,7 @@
        png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
                     PNG_COLOR_TYPE_RGB, png_ptr->interlaced,
                     PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-       data = malloc(im->image->w * 3 * sizeof(char));
-       if (!data)
-         {
-            png_write_end(png_ptr, info_ptr);
-            png_destroy_write_struct(&png_ptr, (png_infopp)&info_ptr);
-            png_destroy_info_struct(png_ptr, (png_infopp)&info_ptr);
-            fclose(f);
-         }
+       data = alloca(im->image->w * 3 * sizeof(char));
      }
    sig_bit.red = 8;
    sig_bit.green = 8;
@@ -136,7 +129,6 @@
             ptr += im->image->w;
          }
      }
-   if (data) free(data);
    png_write_end(png_ptr, info_ptr);
    png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
    png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
@@ -198,12 +190,10 @@
    int                 y = 0;
    int                 i, j;
    
-   buf = malloc(im->image->w * 3 * sizeof(DATA8));
-   if (!buf) return 0;
+   buf = alloca(im->image->w * 3 * sizeof(DATA8));
    f = fopen(file, "wb");
    if (!f)
      {
-       free(buf);
        return 0;
      }
    jerr.pub.error_exit = _JPEGFatalErrorHandler;
@@ -213,7 +203,6 @@
    if (sigsetjmp(jerr.setjmp_buffer, 1))
      {
        jpeg_destroy_compress(&cinfo);
-       free(buf);
        fclose(f);
        return 0;
      }
@@ -242,7 +231,6 @@
      }
    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);
-   free(buf);
    fclose(f);
    return 1;
 }




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to