From: <enl...@li...> - 2005-11-30 08:45:26
|
Enlightenment CVS committal Author : raster Project : e17 Module : libs/evas Dir : e17/libs/evas/src/lib/engines/common Modified Files: evas_font_load.c evas_image_load.c evas_image_main.c Log Message: stringshare works! :) =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_load.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -3 -r1.26 -r1.27 --- evas_font_load.c 29 Nov 2005 09:02:51 -0000 1.26 +++ evas_font_load.c 30 Nov 2005 08:45:20 -0000 1.27 @@ -13,16 +13,13 @@ 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->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; @@ -32,13 +29,10 @@ free(fs); return NULL; } - + fs->name = evas_stringshare_add(name); error = FT_Select_Charmap(fs->ft.face, ft_encoding_unicode); - fs->ft.orig_upem = fs->ft.face->units_per_EM; - fs->references = 1; - fonts_src = evas_object_list_prepend(fonts_src, fs); return fs; } @@ -46,14 +40,11 @@ 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->file = fs->name; fs->data = NULL; fs->data_size = 0; @@ -64,34 +55,10 @@ free(fs); return NULL; } + fs->name = evas_stringshare_add(name); error = FT_Select_Charmap(fs->ft.face, ft_encoding_unicode); - if (error) - { - printf("cant select unicode!\n"); -/* disable this for now... - error = FT_Select_Charmap(fs->ft.face, ft_encoding_latin_2); - if (error) - { - error = FT_Select_Charmap(fs->ft.face, ft_encoding_sjis); - if (error) - { - error = FT_Select_Charmap(fs->ft.face, ft_encoding_gb2312); - if (error) - { - error = FT_Select_Charmap(fs->ft.face, ft_encoding_big5); - if (error) - { - } - } - } - } - */ - } - fs->ft.orig_upem = fs->ft.face->units_per_EM; - fs->references = 1; - fonts_src = evas_object_list_prepend(fonts_src, fs); return fs; } @@ -126,6 +93,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.23 retrieving revision 1.24 diff -u -3 -r1.23 -r1.24 --- evas_image_load.c 29 Nov 2005 09:02:51 -0000 1.23 +++ evas_image_load.c 30 Nov 2005 08:45:20 -0000 1.24 @@ -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.23 retrieving revision 1.24 diff -u -3 -r1.23 -r1.24 --- evas_image_main.c 29 Nov 2005 11:46:20 -0000 1.23 +++ evas_image_main.c 30 Nov 2005 08:45:20 -0000 1.24 @@ -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); } @@ -312,18 +312,6 @@ } void -evas_common_image_free_cache(void) -{ - while (cache) - { - RGBA_Image *im = (RGBA_Image *) cache; - - evas_common_image_uncache(im); - evas_common_image_free(im); - } -} - -void evas_common_image_set_cache(int size) { cache_size = size; @@ -347,23 +335,23 @@ 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); l3 = strlen(buf); - key = malloc(l1 + 5 + l2 + 5 + l3 +1); - if (!key) return; + key = alloca(l1 + 5 + l2 + 5 + l3 +1); 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, "//://"); strcat(key, buf); images = evas_hash_add(images, key, im); - free(key); im->flags |= RGBA_IMAGE_INDEXED; } @@ -377,23 +365,23 @@ 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); l3 = strlen(buf); - key = malloc(l1 + 5 + l2 + 5 + l3 +1); - if (!key) return; + key = alloca(l1 + 5 + l2 + 5 + l3 +1); 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, "//://"); strcat(key, buf); images = evas_hash_del(images, key, im); - free(key); im->flags &= ~RGBA_IMAGE_INDEXED; } @@ -418,12 +406,7 @@ if (key) l2 = strlen(key); snprintf(buf, sizeof(buf), "%llx", timestamp); l3 = strlen(buf); - str = malloc(l1 + 5 + l2 + 5 + l3 +1); - if (!str) - { - if (real_filename) free(real_filename); - return NULL; - } + str = alloca(l1 + 5 + l2 + 5 + l3 +1); str[0] = 0; if (real_filename) strcpy(str, real_filename); else if (filename) strcpy(str, filename); @@ -432,10 +415,9 @@ strcat(str, "//://"); strcat(str, buf); im = evas_hash_find(images, str); - free(str); if (im) { - if (real_filename) free(real_filename); +// if (real_filename) free(real_filename); return im; } @@ -445,6 +427,7 @@ im = (RGBA_Image *)l; ok = 0; +/* if ((real_filename) && (im->info.real_file)) { if ((im->info.real_file) && @@ -453,6 +436,7 @@ ok++; } else + */ { if ((filename) && (im->info.file) && (!strcmp(filename, im->info.file))) @@ -469,11 +453,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; } @@ -484,7 +468,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)) @@ -499,3 +483,15 @@ im->flags |= RGBA_IMAGE_IS_DIRTY; } +void +evas_common_image_free_cache(void) +{ + while (cache) + { + RGBA_Image *im = (RGBA_Image *) cache; + + evas_common_image_uncache(im); + evas_common_image_free(im); + } +} + |