Hi,
Another consuming task was strncpy call when edje manipulate inlined
fonts.
This patch compute at load time a font hash table and pre allocate the needed
string. This reduce lookup time and remove the call to strncpy.
Cedric
Index: src/lib/edje_cache.c
===================================================================
RCS file: /var/cvs/e/e17/libs/edje/src/lib/edje_cache.c,v
retrieving revision 1.6
diff -u -r1.6 edje_cache.c
--- src/lib/edje_cache.c 19 Mar 2006 04:22:35 -0000 1.6
+++ src/lib/edje_cache.c 16 Jun 2006 16:26:53 -0000
@@ -63,6 +63,32 @@
return edc;
}
+static int
+_edje_font_hash (Edje_File *edf)
+{
+ int count = 0;
+
+ if (edf->font_dir)
+ {
+ Evas_List *l;
+ for (l = edf->font_dir->entries; l; l = evas_list_next (l))
+ {
+ Edje_Font_Directory_Entry *fnt = l->data;
+ int length = strlen (fnt->entry) + 7;
+ char *tmp = alloca (length);
+
+ snprintf (tmp, length, "fonts/%s", fnt->entry);
+ fnt->path = evas_stringshare_add (tmp);
+ evas_stringshare_del (fnt->entry);
+ fnt->entry = fnt->path + 6;
+ edf->font_hash = evas_hash_direct_add (edf->font_hash, fnt->entry, fnt);
+
+ count++;
+ }
+ }
+ return count;
+}
+
static Edje_File *
_edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret)
{
@@ -103,18 +129,19 @@
_edje_textblock_style_parse_and_fix(edf);
- if (!coll)
+ if (coll)
{
- eet_close(ef);
- return edf;
+ edc = _edje_file_coll_open(edf, ef, coll);
+ if (!edc)
+ {
+ *error_ret = EDJE_LOAD_ERROR_UNKNOWN_COLLECTION;
+ }
+ if (edc_ret) *edc_ret = edc;
}
+
+ edf->font_hash = NULL;
- edc = _edje_file_coll_open(edf, ef, coll);
- if (!edc)
- {
- *error_ret = EDJE_LOAD_ERROR_UNKNOWN_COLLECTION;
- }
- if (edc_ret) *edc_ret = edc;
+ _edje_font_hash (edf);
eet_close(ef);
return edf;
Index: src/lib/edje_calc.c
===================================================================
RCS file: /var/cvs/e/e17/libs/edje/src/lib/edje_calc.c,v
retrieving revision 1.78
diff -u -r1.78 edje_calc.c
--- src/lib/edje_calc.c 28 Mar 2006 07:45:54 -0000 1.78
+++ src/lib/edje_calc.c 16 Jun 2006 16:26:53 -0000
@@ -592,24 +592,14 @@
if (!text) text = "";
/* check if the font is embedded in the .eet */
- /* FIXME: we should cache this result */
- if (ed->file->font_dir)
+ if (ed->file->font_hash)
{
- Evas_List *l;
-
- for (l = ed->file->font_dir->entries; l; l = l->next)
- {
- Edje_Font_Directory_Entry *fnt = l->data;
+ Edje_Font_Directory_Entry *fnt = evas_hash_find (ed->file->font_hash, font);
- if ((fnt->entry) && (!strcmp(fnt->entry, font)))
- {
- strcpy(buf, "fonts/");
- strncpy(buf + 6, font, sizeof(buf) - 7);
- buf[sizeof(buf) - 1] = 0;
- font = buf;
- inlined_font = 1;
- break;
- }
+ if (fnt)
+ {
+ font = fnt->path;
+ inlined_font = 1;
}
}
if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path);
Index: src/lib/edje_load.c
===================================================================
RCS file: /var/cvs/e/e17/libs/edje/src/lib/edje_load.c,v
retrieving revision 1.84
diff -u -r1.84 edje_load.c
--- src/lib/edje_load.c 28 Mar 2006 07:45:54 -0000 1.84
+++ src/lib/edje_load.c 16 Jun 2006 16:26:53 -0000
@@ -612,7 +612,8 @@
fe = edf->font_dir->entries->data;
edf->font_dir->entries =
evas_list_remove(edf->font_dir->entries, fe);
- if (fe->entry) evas_stringshare_del(fe->entry);
+ edf->font_hash = evas_hash_del (edf->font_hash, fe->entry, NULL);
+ if (fe->path) evas_stringshare_del(fe->path);
free(fe);
}
free(edf->font_dir);
Index: src/lib/edje_private.h
===================================================================
RCS file: /var/cvs/e/e17/libs/edje/src/lib/edje_private.h,v
retrieving revision 1.107
diff -u -r1.107 edje_private.h
--- src/lib/edje_private.h 28 Mar 2006 07:45:54 -0000 1.107
+++ src/lib/edje_private.h 16 Jun 2006 16:26:54 -0000
@@ -201,6 +201,7 @@
int feature_ver;
Evas_Hash *collection_hash;
+ Evas_Hash *font_hash;
Evas_List *collection_cache;
};
@@ -238,6 +239,7 @@
struct _Edje_Font_Directory_Entry
{
char *entry; /* the name of the font */
+ char *path;
};
Index: src/lib/edje_text.c
===================================================================
RCS file: /var/cvs/e/e17/libs/edje/src/lib/edje_text.c,v
retrieving revision 1.53
diff -u -r1.53 edje_text.c
--- src/lib/edje_text.c 28 Mar 2006 07:45:54 -0000 1.53
+++ src/lib/edje_text.c 16 Jun 2006 16:26:54 -0000
@@ -284,24 +284,14 @@
if (!font) font = "";
/* check if the font is embedded in the .eet */
- /* FIXME: we should cache this result */
- if (ed->file->font_dir)
+ if (ed->file->font_hash)
{
- Evas_List *l;
-
- for (l = ed->file->font_dir->entries; l; l = l->next)
+ Edje_Font_Directory_Entry *fnt = evas_hash_find (ed->file->font_hash, font);
+
+ if (fnt)
{
- Edje_Font_Directory_Entry *fnt = l->data;
-
- if ((fnt->entry) && (!strcmp(fnt->entry, font)))
- {
- strcpy(font_buf, "fonts/");
- strncpy(font_buf + 6, font, sizeof(font_buf) - 7);
- font_buf[sizeof(font_buf) - 1] = 0;
- font = font_buf;
- inlined_font = 1;
- break;
- }
+ font = fnt->path;
+ inlined_font = 1;
}
}
Index: src/lib/edje_textblock_styles.c
===================================================================
RCS file: /var/cvs/e/e17/libs/edje/src/lib/edje_textblock_styles.c,v
retrieving revision 1.7
diff -u -r1.7 edje_textblock_styles.c
--- src/lib/edje_textblock_styles.c 28 Mar 2006 16:36:04 -0000 1.7
+++ src/lib/edje_textblock_styles.c 16 Jun 2006 16:26:54 -0000
@@ -8,17 +8,14 @@
static int
_edje_font_is_embedded(Edje_File *edf, char *font)
{
- Evas_List *l;
+ if (!edf->font_hash) return 0;
+
+ Edje_Font_Directory_Entry *fnt = evas_hash_find (edf->font_hash, font);
- if (!edf->font_dir) return 0;
- for (l = edf->font_dir->entries; l; l = l->next)
- {
- Edje_Font_Directory_Entry *fnt = l->data;
-
- if ((fnt->entry) && (!strcmp(fnt->entry, font)))
- return 1;
- }
- return 1;
+ if (fnt)
+ return 1;
+
+ return 0;
}
#if 0
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel