From ab6de960959e455365ec235c42db06284a0b14d5 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 13 May 2007 15:50:11 +0200 Subject: Store glyph names in read-only memory. --- fc-glyphname/fc-glyphname.c | 38 +++++++++----------------------------- src/fcfreetype.c | 12 ++++++++++-- src/fcint.h | 2 +- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/fc-glyphname/fc-glyphname.c b/fc-glyphname/fc-glyphname.c index d4d0b99..0c66165 100644 --- a/fc-glyphname/fc-glyphname.c +++ b/fc-glyphname/fc-glyphname.c @@ -24,9 +24,6 @@ #include "fcint.h" -static int -rawindex (const FcGlyphName *gn); - static void scan (FILE *f, char *filename); @@ -80,17 +77,6 @@ static FcGlyphName *name_to_ucs[MAX_GLYPHNAME*2]; static FcGlyphName *ucs_to_name[MAX_GLYPHNAME*2]; static unsigned int hash, rehash; -static int -rawindex (const FcGlyphName *gn) -{ - int i; - - for (i = 0; i < nraw; i++) - if (raw[i] == gn) - return i; - return -1; -} - static void scan (FILE *f, char *filename) { @@ -219,13 +205,17 @@ dump (FcGlyphName * const *table, const char *name) { int i; - printf ("static const FcGlyphName *%s[%d] = {\n", name, hash); + printf ("static const FcGlyphName %s[%d] = {\n", name, hash); for (i = 0; i < hash; i++) - if (table[i]) - printf ("(FcGlyphName *) &glyph%d,\n", rawindex(table[i])); - else - printf ("0,\n"); + { + FcGlyphName *gn = table[i]; + + if (gn) + printf ("{ 0x%lx, \"%s\" },\n", (unsigned long) gn->ucs, gn->name); + else + printf ("{0},\n"); + } printf ("};\n"); } @@ -285,16 +275,6 @@ main (int argc, char **argv) printf ("#define FC_GLYPHNAME_MAXLEN %d\n\n", max_name_len); /* - * Dump out entries - */ - - 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); - - /* * Dump out name_to_ucs table */ diff --git a/src/fcfreetype.c b/src/fcfreetype.c index c79ab3b..896ff0e 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -2370,7 +2370,9 @@ FcUcs4ToGlyphName (FcChar32 ucs4) int r = 0; const FcGlyphName *gn; - while ((gn = ucs_to_name[i])) + gn = &ucs_to_name[i]; + + while (gn->ucs) { if (gn->ucs == ucs4) return gn->name; @@ -2383,6 +2385,8 @@ FcUcs4ToGlyphName (FcChar32 ucs4) i += r; if (i >= FC_GLYPHNAME_HASH) i -= FC_GLYPHNAME_HASH; + + gn = &ucs_to_name[i]; } return 0; } @@ -2395,7 +2399,9 @@ FcGlyphNameToUcs4 (FcChar8 *name) int r = 0; const FcGlyphName *gn; - while ((gn = name_to_ucs[i])) + gn = &name_to_ucs[i]; + + while (gn->ucs) { if (!strcmp ((char *) name, (char *) gn->name)) return gn->ucs; @@ -2408,6 +2414,8 @@ FcGlyphNameToUcs4 (FcChar8 *name) i += r; if (i >= FC_GLYPHNAME_HASH) i -= FC_GLYPHNAME_HASH; + + gn = &name_to_ucs[i]; } return 0xffff; } diff --git a/src/fcint.h b/src/fcint.h index 4ab4a74..fc43384 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -361,7 +361,7 @@ typedef struct _FcSerialize { typedef struct _FcGlyphName { FcChar32 ucs; /* unicode value */ - FcChar8 name[1]; /* name extends beyond struct */ + FcChar8 name[]; /* name extends beyond struct */ } FcGlyphName; /* -- 1.5.1.3