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

:)


SVN revision: 18679
This commit is contained in:
Carsten Haitzler 2005-11-28 15:18:01 +00:00
parent 6197f4b476
commit aaf6e303bd
19 changed files with 320 additions and 169 deletions

View File

@ -16,6 +16,7 @@ AC_HEADER_STDC
AC_C_CONST
AM_ENABLE_SHARED
AM_PROG_LIBTOOL
AC_FUNC_ALLOCA
dnl Add the languages which your application supports here.

View File

@ -300,6 +300,7 @@ extern "C" {
* do we really need this? hmmm - let me think... there may be a better way
*/
EAPI Evas_Hash *evas_hash_add (Evas_Hash *hash, const char *key, const void*data);
EAPI Evas_Hash *evas_hash_direct_add (Evas_Hash *hash, const char *key, const void*data);
EAPI Evas_Hash *evas_hash_del (Evas_Hash *hash, const char *key, const void*data);
EAPI void *evas_hash_find (Evas_Hash *hash, const char *key);
EAPI void *evas_hash_modify (Evas_Hash *hash, const char *key, const void*data);
@ -307,6 +308,10 @@ extern "C" {
EAPI void evas_hash_free (Evas_Hash *hash);
EAPI void evas_hash_foreach (Evas_Hash *hash, Evas_Bool (*func) (Evas_Hash *hash, const char *key, void *data, void *fdata), const void *fdata);
EAPI int evas_hash_alloc_error (void);
EAPI const char *evas_stringshare_add (const char *str);
EAPI void evas_stringshare_del (const char *str);
EAPI int evas_alloc_error (void);

View File

@ -94,7 +94,7 @@ evas_font_set_get(const char *name)
p = strchr(name, ',');
if (!p)
{
fonts = evas_list_append(fonts, strdup(name));
fonts = evas_list_append(fonts, evas_stringshare_add(name));
}
else
{
@ -110,7 +110,7 @@ evas_font_set_get(const char *name)
fonts = evas_list_append(fonts, nm);
pp = p + 1;
p = strchr(pp, ',');
if (!p) fonts = evas_list_append(fonts, strdup(pp));
if (!p) fonts = evas_list_append(fonts, evas_stringshare_add(pp));
}
}
return fonts;
@ -145,8 +145,8 @@ evas_font_free(Evas *evas, void *font)
fd = evas_list_data(fonts_zero);
if (fd->ref != 0) break;
fonts_zero = evas_list_remove_list(fonts_zero, fonts_zero);
if (fd->name) free(fd->name);
if (fd->source) free(fd->source);
if (fd->name) evas_stringshare_del(fd->name);
if (fd->source) evas_stringshare_del(fd->source);
evas->engine.func->font_free(evas->engine.data.output, fd->font);
free(fd);
}
@ -323,14 +323,14 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
}
#endif
}
free(nm);
evas_stringshare_del(nm);
}
evas_list_free(fonts);
fd = calloc(1, sizeof(Fndat));
if (fd)
{
fd->name = strdup(name);
if (source) fd->source = strdup(source);
fd->name = evas_stringshare_add(name);
if (source) fd->source = evas_stringshare_add(source);
fd->size = size;
fd->font = font;
fd->ref = 1;
@ -525,7 +525,7 @@ object_text_font_cache_dir_add(char *dir)
fn->type = 1;
for (i = 0; i < 14; i++)
{
fn->x.prop[i] = strdup(font_prop[i]);
fn->x.prop[i] = evas_stringshare_add(font_prop[i]);
/* FIXME: what if strdup fails! */
}
fn->path = evas_file_path_join(dir, fname);
@ -553,7 +553,7 @@ object_text_font_cache_dir_add(char *dir)
if (fn)
{
fn->type = 0;
fn->simple.name = strdup(fdir->data);
fn->simple.name = evas_stringshare_add(fdir->data);
if (fn->simple.name)
{
char *p;
@ -591,11 +591,11 @@ object_text_font_cache_dir_add(char *dir)
fa = calloc(1, sizeof(Evas_Font_Alias));
if (fa)
{
fa->alias = strdup(fname);
fa->alias = evas_stringshare_add(fname);
fa->fn = object_text_font_cache_font_find_x(fd, fdef);
if ((!fa->alias) || (!fa->fn))
{
if (fa->alias) free(fa->alias);
if (fa->alias) evas_stringshare_del(fa->alias);
free(fa);
}
else
@ -637,10 +637,10 @@ object_text_font_cache_dir_del(char *dir, Evas_Font_Dir *fd)
fd->fonts = evas_list_remove(fd->fonts, fn);
for (i = 0; i < 14; i++)
{
if (fn->x.prop[i]) free(fn->x.prop[i]);
if (fn->x.prop[i]) evas_stringshare_del(fn->x.prop[i]);
}
if (fn->simple.name) free(fn->simple.name);
if (fn->path) free(fn->path);
if (fn->simple.name) evas_stringshare_del(fn->simple.name);
if (fn->path) evas_stringshare_del(fn->path);
free(fn);
}
while (fd->aliases)
@ -649,7 +649,7 @@ object_text_font_cache_dir_del(char *dir, Evas_Font_Dir *fd)
fa = fd->aliases->data;
fd->aliases = evas_list_remove(fd->aliases, fa);
if (fa->alias) free(fa->alias);
if (fa->alias) evas_stringshare_del(fa->alias);
free(fa);
}
free(fd);

View File

@ -22,13 +22,13 @@ evas_object_name_set(Evas_Object *obj, const char *name)
if (obj->name)
{
obj->layer->evas->name_hash = evas_hash_del(obj->layer->evas->name_hash, obj->name, obj);
free(obj->name);
evas_stringshare_del(obj->name);
}
if (!name) obj->name = NULL;
else
{
obj->name = strdup(name);
obj->layer->evas->name_hash = evas_hash_add(obj->layer->evas->name_hash, obj->name, obj);
obj->name = evas_stringshare_add(name);
obj->layer->evas->name_hash = evas_hash_direct_add(obj->layer->evas->name_hash, obj->name, obj);
}
}

View File

@ -138,11 +138,11 @@ evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
if ((o->cur.key) && (key) && (!strcmp(o->cur.key, key)))
return;
}
if (o->cur.file) free(o->cur.file);
if (o->cur.key) free(o->cur.key);
if (file) o->cur.file = strdup(file);
if (o->cur.file) evas_stringshare_del(o->cur.file);
if (o->cur.key) evas_stringshare_del(o->cur.key);
if (file) o->cur.file = evas_stringshare_add(file);
else o->cur.file = NULL;
if (key) o->cur.key = strdup(key);
if (key) o->cur.key = evas_stringshare_add(key);
else o->cur.key = NULL;
o->prev.file = NULL;
o->prev.key = NULL;
@ -1330,8 +1330,8 @@ evas_object_image_free(Evas_Object *obj)
return;
MAGIC_CHECK_END();
/* free obj */
if (o->cur.file) free(o->cur.file);
if (o->cur.key) free(o->cur.key);
if (o->cur.file) evas_stringshare_del(o->cur.file);
if (o->cur.key) evas_stringshare_del(o->cur.key);
if (o->engine_data)
obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
o->engine_data);

View File

@ -27,11 +27,6 @@ evas_object_free(Evas_Object *obj, int clean_layer)
obj->func->free(obj);
if (obj->name) evas_object_name_set(obj, NULL);
if (!was_smart_child) evas_object_release(obj, clean_layer);
if (obj->name)
{
free(obj->name);
obj->name = NULL;
}
if (obj->clip.clipees)
evas_list_free(obj->clip.clipees);
while (obj->clip.changes)

View File

@ -225,7 +225,7 @@ evas_object_smart_callback_add(Evas_Object *obj, const char *event, void (*func)
if (!event) return;
if (!func) return;
cb = calloc(1, sizeof(Evas_Smart_Callback));
cb->event = strdup(event);
cb->event = evas_stringshare_add(event);
cb->func = func;
cb->func_data = (void *)data;
obj->smart.callbacks = evas_list_prepend(obj->smart.callbacks, cb);
@ -326,7 +326,7 @@ evas_object_smart_callbacks_clear(Evas_Object *obj)
if (cb->delete_me)
{
obj->smart.callbacks = evas_list_remove(obj->smart.callbacks, cb);
if (cb->event) free(cb->event);
if (cb->event) evas_stringshare_add(cb->event);
free(cb);
}
}
@ -359,7 +359,7 @@ evas_object_smart_cleanup(Evas_Object *obj)
cb = obj->smart.callbacks->data;
obj->smart.callbacks = evas_list_remove(obj->smart.callbacks, cb);
if (cb->event) free(cb->event);
if (cb->event) evas_stringshare_add(cb->event);
free(cb);
}
obj->smart.parent = NULL;

View File

@ -108,8 +108,8 @@ evas_object_text_font_source_set(Evas_Object *obj, const char *font_source)
if ((o->cur.source) && (font_source) &&
(!strcmp(o->cur.source, font_source)))
return;
if (o->cur.source) free(o->cur.source);
if (font_source) o->cur.source = strdup(font_source);
if (o->cur.source) evas_stringshare_del(o->cur.source);
if (font_source) o->cur.source = evas_stringshare_add(font_source);
else o->cur.source = NULL;
}
@ -179,8 +179,8 @@ evas_object_text_font_set(Evas_Object *obj, const char *font, Evas_Font_Size siz
o->engine_data = evas_font_load(obj->layer->evas, font, o->cur.source, size);
if (!same_font)
{
if (o->cur.font) free(o->cur.font);
if (font) o->cur.font = strdup(font);
if (o->cur.font) evas_stringshare_del(o->cur.font);
if (font) o->cur.font = evas_stringshare_add(font);
else o->cur.font = NULL;
o->prev.font = NULL;
}
@ -293,8 +293,8 @@ evas_object_text_text_set(Evas_Object *obj, const char *text)
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y, 1, 1);
/* DO II */
if (o->cur.text) free(o->cur.text);
if (text && *text) o->cur.text = strdup(text);
if (o->cur.text) evas_stringshare_del(o->cur.text);
if (text && *text) o->cur.text = evas_stringshare_add(text);
else o->cur.text = NULL;
o->prev.text = NULL;
if ((o->engine_data) && (o->cur.text))
@ -917,7 +917,7 @@ evas_font_path_clear(Evas *e)
MAGIC_CHECK_END();
while (e->font_path)
{
free(e->font_path->data);
evas_stringshare_del(e->font_path->data);
e->font_path = evas_list_remove(e->font_path, e->font_path->data);
}
}
@ -935,7 +935,7 @@ evas_font_path_append(Evas *e, const char *path)
return;
MAGIC_CHECK_END();
if (!path) return;
e->font_path = evas_list_append(e->font_path, strdup(path));
e->font_path = evas_list_append(e->font_path, evas_stringshare_add(path));
}
/**
@ -951,7 +951,7 @@ evas_font_path_prepend(Evas *e, const char *path)
return;
MAGIC_CHECK_END();
if (!path) return;
e->font_path = evas_list_prepend(e->font_path, strdup(path));
e->font_path = evas_list_prepend(e->font_path, evas_stringshare_add(path));
}
/**
@ -1197,9 +1197,9 @@ evas_object_text_free(Evas_Object *obj)
return;
MAGIC_CHECK_END();
/* free obj */
if (o->cur.text) free(o->cur.text);
if (o->cur.font) free(o->cur.font);
if (o->cur.source) free(o->cur.source);
if (o->cur.text) evas_stringshare_del(o->cur.text);
if (o->cur.font) evas_stringshare_del(o->cur.font);
if (o->cur.source) evas_stringshare_del(o->cur.source);
if (o->engine_data) evas_font_free(obj->layer->evas, o->engine_data);
o->magic = 0;
free(o);

View File

@ -14,6 +14,7 @@ noinst_LTLIBRARIES = libevas_data.la
libevas_data_la_SOURCES = \
evas_hash.c \
evas_list.c \
evas_object_list.c
evas_object_list.c \
evas_stringshare.c
libevas_data_la_DEPENDENCIES = $(top_builddir)/config.h

View File

@ -117,7 +117,70 @@ evas_hash_add(Evas_Hash *hash, const char *key, const void *data)
if (evas_list_alloc_error())
{
_evas_hash_alloc_error = 1;
if (el->key) free(el->key);
free(el);
return hash;
}
hash->population++;
return hash;
}
/**
* Adds an entry to the given hash table and does not duplicate the string key.
*
* @p key is expected to be a unique string within the hash table.
* Otherwise, you cannot be sure which inserted data pointer will be
* accessed with @ref evas_hash_find , and removed with
* @ref evas_hash_del . This call does nto make a copy of the key so it must
* be a string constant or stored elsewhere (in the object being added) etc.
*
* Key strings are case sensitive.
*
* @ref evas_hash_alloc_error should be used to determine if an
* allocation error occurred during this function.
*
* @param hash The given hash table. Can be @c NULL, in which case a
* new hash table is allocated and returned.
* @param key A unique string. Can be @c NULL.
* @param data Data to associate with the string given by @p key.
* @return Either the given hash table, or if the given value for @p
* hash is @c NULL, then a new one. @c NULL will be returned
* if memory could not be allocated for a new table.
* @ingroup Evas_Hash_Data
*/
Evas_Hash *
evas_hash_direct_add(Evas_Hash *hash, const char *key, const void *data)
{
int hash_num;
Evas_Hash_El *el;
if ((!key) || (!data)) return hash;
_evas_hash_alloc_error = 0;
if (!hash)
{
hash = calloc(1, sizeof(struct _Evas_Hash));
if (!hash)
{
_evas_hash_alloc_error = 1;
return NULL;
}
}
if (!(el = malloc(sizeof(struct _Evas_Hash_El))))
{
if (hash->population <= 0)
{
free(hash);
hash = NULL;
}
_evas_hash_alloc_error = 1;
return hash;
};
el->key = key;
el->data = (void *)data;
hash_num = _evas_hash_gen(key);
hash->buckets[hash_num] = evas_object_list_prepend(hash->buckets[hash_num], el);
if (evas_list_alloc_error())
{
_evas_hash_alloc_error = 1;
free(el);
return hash;
}

View File

@ -0,0 +1,115 @@
#include "evas_common.h"
#include "evas_private.h"
typedef struct _Evas_Stringshare Evas_Stringshare;
typedef struct _Evas_Stringshare_El Evas_Stringshare_El;
struct _Evas_Stringshare
{
Evas_Object_List *buckets[256];
};
struct _Evas_Stringshare_El
{
Evas_Object_List _list_data;
char *str;
int references;
};
static inline int _evas_stringshare_hash_gen(const char *str);
static inline int
_evas_stringshare_hash_gen(const char *str)
{
unsigned int hash_num = 0, i;
const unsigned char *ptr;
if (!str) return 0;
for (i = 0, ptr = (unsigned char *)str; *ptr; ptr++, i++)
hash_num ^= ((int)(*ptr) | ((int)(*ptr) << 8)) >> (i % 8);
hash_num &= 0xff;
return (int)hash_num;
}
static Evas_Stringshare share =
{
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
}
};
const char *
evas_stringshare_add(const char *str)
{
int hash_num;
Evas_Stringshare_El *el;
Evas_Object_List *l;
hash_num = _evas_stringshare_hash_gen(str);
for (l = share.buckets[hash_num]; l; l = l->next)
{
el = (Evas_Stringshare_El *)l;
if (!strcmp(el->str, str))
{
if (l != share.buckets[hash_num])
{
share.buckets[hash_num] = evas_object_list_remove(share.buckets[hash_num], el);
share.buckets[hash_num] = evas_object_list_prepend(share.buckets[hash_num], el);
}
el->references++;
return el->str;
}
}
if (!(el = malloc(sizeof(struct _Evas_Stringshare_El) + strlen(str) + 1))) return NULL;
el->str = ((unsigned char *)el) + sizeof(struct _Evas_Stringshare_El);
strcpy(el->str, str);
el->references = 1;
share.buckets[hash_num] = evas_object_list_prepend(share.buckets[hash_num], el);
return el->str;
}
void
evas_stringshare_del(const char *str)
{
int hash_num;
Evas_Stringshare_El *el;
Evas_Object_List *l;
hash_num = _evas_stringshare_hash_gen(str);
for (l = share.buckets[hash_num]; l; l = l->next)
{
el = (Evas_Stringshare_El *)l;
if (!strcmp(el->str, str))
{
el->references--;
if (el->references == 0)
{
share.buckets[hash_num] = evas_object_list_remove(share.buckets[hash_num], el);
free(el);
}
else
{
share.buckets[hash_num] = evas_object_list_remove(share.buckets[hash_num], el);
share.buckets[hash_num] = evas_object_list_prepend(share.buckets[hash_num], el);
}
return;
}
}
}

View File

@ -227,54 +227,50 @@ evas_common_font_draw(RGBA_Image *dst, RGBA_Draw_Context *dc, RGBA_Font *fn, int
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)
{
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);
}
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);
}
}
free(tmpbuf);
}
}
}

View File

@ -13,22 +13,21 @@ static Evas_Bool font_flush_free_glyph_cb(Evas_Hash *hash, const char *key, void
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 @@ evas_common_font_source_memory_load(const char *name, const void *data, int data
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 @@ evas_common_font_source_load(const char *name)
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 @@ evas_common_font_source_free(RGBA_Font_Source *fs)
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);
}

View File

@ -200,15 +200,8 @@ load_image_file_data_png(RGBA_Image *im, const char *file, const char *key)
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 @@ load_image_file_data_png(RGBA_Image *im, const char *file, const char *key)
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 @@ load_image_file_data_jpeg_internal(RGBA_Image *im, FILE *f)
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 @@ load_image_file_data_jpeg_internal(RGBA_Image *im, FILE *f)
}
}
}
free(data);
/* end data decoding */
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
@ -457,15 +442,9 @@ load_image_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f)
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 @@ load_image_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f)
}
}
}
free(data);
/* end data decoding */
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
@ -958,15 +936,14 @@ evas_common_load_image_from_file(const char *file, const char *key)
// 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;
}

View File

@ -227,10 +227,10 @@ void
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 @@ evas_common_image_store(RGBA_Image *im)
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 @@ evas_common_image_store(RGBA_Image *im)
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 @@ evas_common_image_unstore(RGBA_Image *im)
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 @@ evas_common_image_unstore(RGBA_Image *im)
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 @@ evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
free(str);
if (im)
{
if (real_filename) free(real_filename);
// if (real_filename) free(real_filename);
return im;
}
@ -433,6 +437,7 @@ evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
im = (RGBA_Image *)l;
ok = 0;
/*
if ((real_filename) && (im->info.real_file))
{
if ((im->info.real_file) &&
@ -441,6 +446,7 @@ evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
ok++;
}
else
*/
{
if ((filename) && (im->info.file) &&
(!strcmp(filename, im->info.file)))
@ -457,11 +463,11 @@ evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
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 @@ evas_common_image_ram_usage(RGBA_Image *im)
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))

View File

@ -94,14 +94,7 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
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 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
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 @@ save_image_jpeg(RGBA_Image *im, const char *file, int quality)
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 @@ save_image_jpeg(RGBA_Image *im, const char *file, int quality)
if (sigsetjmp(jerr.setjmp_buffer, 1))
{
jpeg_destroy_compress(&cinfo);
free(buf);
fclose(f);
return 0;
}
@ -242,7 +231,6 @@ save_image_jpeg(RGBA_Image *im, const char *file, int quality)
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
free(buf);
fclose(f);
return 1;
}

View File

@ -86,8 +86,7 @@ _xre_font_surface_new(Ximage_Info *xinf, RGBA_Font_Glyph *fg)
int bi, bj, end;
const DATA8 bitrepl[2] = {0x0, 0xff};
tmpbuf = malloc(w);
if (tmpbuf)
tmpbuf = alloca(w);
{
int x, y;
DATA8 *p1, *p2;
@ -117,7 +116,6 @@ _xre_font_surface_new(Ximage_Info *xinf, RGBA_Font_Glyph *fg)
p2++;
}
}
free(tmpbuf);
}
}
_xr_image_put(xim, fs->draw, 0, 0, w, h);

View File

@ -94,15 +94,15 @@ _xre_image_load(Ximage_Info *xinf, char *file, char *key)
im->xinf = xinf;
im->xinf->references++;
im->fkey = strdup(buf);
im->file = strdup(file);
if (key) im->key = strdup(key);
im->file = evas_stringshare_add(file);
if (key) im->key = evas_stringshare_add(key);
im->w = im->im->image->w;
im->h = im->im->image->h;
im->references = 1;
if (im->im->info.comment) im->comment = strdup(im->im->info.comment);
if (im->im->info.format == 1) im->format = strdup("png");
if (im->im->info.comment) im->comment = evas_stringshare_add(im->im->info.comment);
if (im->im->info.format == 1) im->format = evas_stringshare_add("png");
if (im->im->flags & RGBA_IMAGE_HAS_ALPHA) im->alpha = 1;
_xr_image_hash = evas_hash_add(_xr_image_hash, im->fkey, im);
_xr_image_hash = evas_hash_direct_add(_xr_image_hash, im->fkey, im);
return im;
}
@ -186,15 +186,15 @@ _xre_image_new(Ximage_Info *xinf, int w, int h)
static void
__xre_image_real_free(XR_Image *im)
{
if (im->file) free(im->file);
if (im->key) free(im->key);
if (im->file) evas_stringshare_del(im->file);
if (im->key) evas_stringshare_del(im->key);
if (im->fkey) free(im->fkey);
if (im->im) evas_common_image_unref(im->im);
if ((im->data) && (im->dirty)) __xre_image_dirty_hash_del(im);
if ((im->free_data) && (im->data)) free(im->data);
if (im->surface) _xr_render_surface_free(im->surface);
if (im->format) free(im->format);
if (im->comment) free(im->comment);
if (im->format) evas_stringshare_del(im->format);
if (im->comment) evas_stringshare_del(im->comment);
if (im->updates) evas_common_tilebuf_free(im->updates);
_xr_image_info_free(im->xinf);
free(im);

View File

@ -42,6 +42,10 @@
#include <sys/types.h>
#include <ctype.h>
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifdef _WIN32_WCE
#include <windows.h>
#endif
@ -210,7 +214,7 @@ struct _RGBA_Image
{
int format;
char *file;
char *real_file;
// char *real_file;
char *key;
char *comment;
} info;
@ -571,6 +575,9 @@ void evas_hash_free (Evas_Hash *hash);
void evas_hash_foreach (Evas_Hash *hash, Evas_Bool (*func) (Evas_Hash *hash, const char *key, void *data, void *fdata), const void *fdata);
int evas_hash_alloc_error (void);
const char *evas_stringshare_add (const char *str);
void evas_stringshare_del (const char *str);
void *evas_object_list_append (void *in_list, void *in_item);
void *evas_object_list_prepend (void *in_list, void *in_item);
void *evas_object_list_append_relative (void *in_list, void *in_item, void *in_relative);