From 96925b99c0551c4ed6bf7099473d0d36964f52cd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 18 Oct 2007 09:43:22 -0700 Subject: [PATCH] Eliminate relocations for glyph name table. Glyph names (now used only for dingbats) were using many relocations, causing startup latency plus per-process memory usage. Replace pointers with table indices, shrinking table size and elimninating relocations. --- fc-glyphname/fc-glyphname.c | 28 ++++++++++++++++++++-------- src/fcfreetype.c | 16 ++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/fc-glyphname/fc-glyphname.c b/fc-glyphname/fc-glyphname.c index d4d0b99..b63ed24 100644 --- a/fc-glyphname/fc-glyphname.c +++ b/fc-glyphname/fc-glyphname.c @@ -217,15 +217,15 @@ insert (FcGlyphName *gn, FcGlyphName **table, FcChar32 h) static void dump (FcGlyphName * const *table, const char *name) { - int i; + int i; - printf ("static const FcGlyphName *%s[%d] = {\n", name, hash); + printf ("static const FcGlyphId %s[%d] = {\n", name, hash); for (i = 0; i < hash; i++) if (table[i]) - printf ("(FcGlyphName *) &glyph%d,\n", rawindex(table[i])); + printf (" %d,\n", rawindex(table[i])); else - printf ("0,\n"); + printf (" -1,\n"); printf ("};\n"); } @@ -237,6 +237,7 @@ main (int argc, char **argv) char line[1024]; FILE *f; int i; + char *type; i = 0; while (argv[i+1]) @@ -283,16 +284,27 @@ main (int argc, char **argv) printf ("#define FC_GLYPHNAME_HASH %u\n", hash); printf ("#define FC_GLYPHNAME_REHASH %u\n", rehash); printf ("#define FC_GLYPHNAME_MAXLEN %d\n\n", max_name_len); + if (nraw < 128) + type = "int8_t"; + else if (nraw < 32768) + type = "int16_t"; + else + type = "int32_t"; + + printf ("typedef %s FcGlyphId;\n\n", type); /* * Dump out entries */ + printf ("static const struct { const FcChar32 ucs; const FcChar8 name[%d]; } glyphs[%d] = {\n", + max_name_len + 1, nraw); + for (i = 0; i < nraw; i++) - printf ("static const struct { const FcChar32 ucs; const FcChar8 name[%d]; }" - " glyph%d = { 0x%lx, \"%s\" };\n", - (int) strlen ((char *) raw[i]->name) + 1, - i, (unsigned long) raw[i]->ucs, raw[i]->name); + printf (" { 0x%lx, \"%s\" },\n", + (unsigned long) raw[i]->ucs, raw[i]->name); + + printf ("};\n"); /* * Dump out name_to_ucs table diff --git a/src/fcfreetype.c b/src/fcfreetype.c index fb2e01b..c9c58c7 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -2304,12 +2304,12 @@ FcUcs4ToGlyphName (FcChar32 ucs4) { int i = (int) (ucs4 % FC_GLYPHNAME_HASH); int r = 0; - const FcGlyphName *gn; + FcGlyphId gn; - while ((gn = ucs_to_name[i])) + while ((gn = ucs_to_name[i]) != -1) { - if (gn->ucs == ucs4) - return gn->name; + if (glyphs[gn].ucs == ucs4) + return glyphs[gn].name; if (!r) { r = (int) (ucs4 % FC_GLYPHNAME_REHASH); @@ -2329,12 +2329,12 @@ FcGlyphNameToUcs4 (FcChar8 *name) FcChar32 h = FcHashGlyphName (name); int i = (int) (h % FC_GLYPHNAME_HASH); int r = 0; - const FcGlyphName *gn; + FcGlyphId gn; - while ((gn = name_to_ucs[i])) + while ((gn = name_to_ucs[i]) != -1) { - if (!strcmp ((char *) name, (char *) gn->name)) - return gn->ucs; + if (!strcmp ((char *) name, (char *) glyphs[gn].name)) + return glyphs[gn].ucs; if (!r) { r = (int) (h % FC_GLYPHNAME_REHASH); -- 2.7.4