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.
This commit is contained in:
Keith Packard 2007-10-18 09:43:22 -07:00
parent bc5e8adb4d
commit 96925b99c0
2 changed files with 28 additions and 16 deletions

View File

@ -219,13 +219,13 @@ dump (FcGlyphName * const *table, const char *name)
{
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

View File

@ -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);