diff options
author | Keith Packard <keithp@neko.keithp.com> | 2006-08-30 04:16:22 -0700 |
---|---|---|
committer | Keith Packard <keithp@neko.keithp.com> | 2006-08-30 04:16:22 -0700 |
commit | 7ce196733129b0e664c1bdc20f973f15167292f7 (patch) | |
tree | e63deabfdbe65246cf4ed53187e04e09a0027886 /fc-lang/fc-lang.c | |
parent | 2a9179d8895c1cc90d02917f7bb6fac30ffb6a62 (diff) |
Rework cache files to use offsets for all data structures.
Replace all of the bank/id pairs with simple offsets, recode several
data structures to always use offsets inside the library to avoid
conditional paths. Exposed data structures use pointers to hold offsets,
setting the low bit to distinguish between offset and pointer.
Use offset-based data structures for lang charset encodings; eliminates
separate data structure format for that file.
Much testing will be needed; offsets are likely not detected everywhere in
the library yet.
Diffstat (limited to 'fc-lang/fc-lang.c')
-rw-r--r-- | fc-lang/fc-lang.c | 185 |
1 files changed, 90 insertions, 95 deletions
diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c index b72893b..631411d 100644 --- a/fc-lang/fc-lang.c +++ b/fc-lang/fc-lang.c @@ -37,10 +37,6 @@ * functions are also needed in slightly modified form */ -const FcChar16 langBankNumbers[1]; /* place holders so that externs resolve */ -const FcCharLeaf langBankLeaves[1]; -const int langBankLeafIdx[1]; - void FcMemAlloc (int kind, int size) { @@ -51,18 +47,6 @@ FcMemFree (int kind, int size) { } -int* _fcBankId = 0; -int* _fcBankIdx = 0; -FcValueList ** _fcValueLists = 0; -FcPatternElt ** _fcPatternElts = 0; -int FcDebugVal = 0; - -int -FcCacheBankToIndexMTF (int bank) -{ - return -1; -} - FcChar8 * FcConfigHome (void) { @@ -239,19 +223,18 @@ main (int argc, char **argv) static char *files[MAX_LANG]; static FcCharSet *sets[MAX_LANG]; static int duplicate[MAX_LANG]; - static int offsets[MAX_LANG]; static int country[MAX_LANG]; static char *names[MAX_LANG]; static char *langs[MAX_LANG]; + static int off[MAX_LANG]; FILE *f; - int offset = 0; int ncountry = 0; int i = 0; + int nsets = 0; int argi; FcCharLeaf **leaves; int total_leaves = 0; - int offset_count = 0; - int l, sl, tl; + int l, sl, tl, tn; static char line[1024]; static FcChar32 map[MAX_LANG_SET_MAP]; int num_lang_set_map; @@ -290,6 +273,7 @@ main (int argc, char **argv) i++; fclose (f); } + nsets = i; sets[i] = 0; leaves = malloc (total_leaves * sizeof (FcCharLeaf *)); tl = 0; @@ -301,10 +285,10 @@ main (int argc, char **argv) for (sl = 0; sl < sets[i]->num; sl++) { for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetGetLeaf(sets[i], sl)) + if (leaves[l] == FcCharSetLeaf(sets[i], sl)) break; if (l == tl) - leaves[tl++] = FcCharSetGetLeaf(sets[i], sl); + leaves[tl++] = FcCharSetLeaf(sets[i], sl); } } @@ -321,22 +305,6 @@ main (int argc, char **argv) printf ("/* total size: %d unique leaves: %d */\n\n", total_leaves, tl); - /* - * Dump leaves - */ - printf ("const FcCharLeaf langBankLeaves[%d] = {\n", tl); - for (l = 0; l < tl; l++) - { - printf (" { { /* %d */", l); - for (i = 0; i < 256/32; i++) - { - if (i % 4 == 0) - printf ("\n "); - printf (" 0x%08x,", leaves[l]->map[i]); - } - printf ("\n } },\n"); - } - printf ("};\n\n"); /* * Find duplicate charsets @@ -355,111 +323,121 @@ main (int argc, char **argv) } } + tn = 0; + for (i = 0; sets[i]; i++) { + if (duplicate[i] >= 0) + continue; + off[i] = tn; + tn += sets[i]->num; + } + + printf ("#define LEAF0 (%d * sizeof (FcLangCharSet))\n", nsets); + printf ("#define OFF0 (LEAF0 + %d * sizeof (FcCharLeaf))\n", tl); + printf ("#define NUM0 (OFF0 + %d * sizeof (intptr_t))\n", tn); + printf ("#define SET(n) (n * sizeof (FcLangCharSet) + offsetof (FcLangCharSet, charset))\n"); + printf ("#define OFF(s,o) (OFF0 + o * sizeof (intptr_t) - SET(s))\n"); + printf ("#define NUM(s,n) (NUM0 + n * sizeof (FcChar16) - SET(s))\n"); + printf ("#define LEAF(o,l) (LEAF0 + l * sizeof (FcCharLeaf) - (OFF0 + o * sizeof (intptr_t)))\n"); + printf ("#define fcLangCharSets (fcLangData.langCharSets)\n"); + printf ("\n"); + + printf ("static const struct {\n" + " FcLangCharSet langCharSets[%d];\n" + " FcCharLeaf leaves[%d];\n" + " intptr_t leaf_offsets[%d];\n" + " FcChar16 numbers[%d];\n" + "} fcLangData = {\n", + nsets, tl, tn, tn); + /* - * Find ranges for each letter for faster searching + * Dump sets */ - setRangeChar = 'a'; + + printf ("{\n"); for (i = 0; sets[i]; i++) { - char c = names[i][0]; - - while (setRangeChar <= c && c <= 'z') - setRangeStart[setRangeChar++ - 'a'] = i; + int j = duplicate[i]; + + if (j < 0) + j = i; + + printf (" { (FcChar8 *) \"%s\", " + " { FC_REF_CONSTANT, %d, OFF(%d,%d), NUM(%d,%d) } }, /* %d */\n", + langs[i], + sets[j]->num, i, off[j], i, off[j], i); } - for (setRangeChar = 'a'; setRangeChar < 'z'; setRangeChar++) - setRangeEnd[setRangeChar - 'a'] = setRangeStart[setRangeChar+1-'a'] - 1; - setRangeEnd[setRangeChar - 'a'] = i - 1; + printf ("},\n"); /* - * Dump arrays + * Dump leaves */ - for (i = 0; sets[i]; i++) + printf ("{\n"); + for (l = 0; l < tl; l++) { - int n; - - if (duplicate[i] >= 0) - continue; - - for (n = 0; n < sets[i]->num; n++) + printf (" { { /* %d */", l); + for (i = 0; i < 256/32; i++) { - for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetGetLeaf(sets[i], n)) - break; - if (l == tl) - fatal (names[i], 0, "can't find leaf"); - offset_count++; + if (i % 4 == 0) + printf ("\n "); + printf (" 0x%08x,", leaves[l]->map[i]); } - offsets[i] = offset; - offset += sets[i]->num; + printf ("\n } },\n"); } + printf ("},\n"); - printf ("const int langBankLeafIdx[%d] = {\n", - offset_count); + /* + * Dump leaves + */ + printf ("{\n"); for (i = 0; sets[i]; i++) { int n; if (duplicate[i] >= 0) continue; + printf (" /* %s */\n", names[i]); for (n = 0; n < sets[i]->num; n++) { - if (n % 8 == 0) + if (n % 4 == 0) printf (" "); for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetGetLeaf(sets[i], n)) + if (leaves[l] == FcCharSetLeaf(sets[i], n)) break; if (l == tl) fatal (names[i], 0, "can't find leaf"); - printf (" %3d,", l); - if (n % 8 == 7) + printf (" LEAF(%3d,%3d),", off[i], l); + if (n % 4 == 3) printf ("\n"); } - if (n % 8 != 0) + if (n % 4 != 0) printf ("\n"); } - printf ("};\n\n"); - - printf ("const FcChar16 langBankNumbers[%d] = {\n", - offset_count); + printf ("},\n"); + + printf ("{\n"); for (i = 0; sets[i]; i++) { int n; - + if (duplicate[i] >= 0) continue; + printf (" /* %s */\n", names[i]); for (n = 0; n < sets[i]->num; n++) { if (n % 8 == 0) printf (" "); - printf (" 0x%04x,", FcCharSetGetNumbers(sets[i])[n]); + printf (" 0x%04x,", FcCharSetNumbers (sets[i])[n]); if (n % 8 == 7) printf ("\n"); } if (n % 8 != 0) printf ("\n"); } - printf ("};\n\n"); + printf ("}\n"); - /* - * Dump sets - */ - - printf ("const FcLangCharSet fcLangCharSets[] = {\n"); - for (i = 0; sets[i]; i++) - { - int j = duplicate[i]; - - if (j < 0) - j = i; - - printf (" { (FcChar8 *) \"%s\",\n" - " { FC_REF_CONSTANT, %d, FC_BANK_LANGS, " - "{ { %d, %d } } } }, /* %d */\n", - langs[i], - sets[j]->num, offsets[j], offsets[j], j); - } printf ("};\n\n"); + printf ("#define NUM_LANG_CHAR_SET %d\n", i); num_lang_set_map = (i + 31) / 32; printf ("#define NUM_LANG_SET_MAP %d\n", num_lang_set_map); @@ -507,6 +485,23 @@ main (int argc, char **argv) /* + * Find ranges for each letter for faster searching + */ + setRangeChar = 'a'; + memset(setRangeStart, '\0', sizeof (setRangeStart)); + memset(setRangeEnd, '\0', sizeof (setRangeEnd)); + for (i = 0; sets[i]; i++) + { + char c = names[i][0]; + + while (setRangeChar <= c && c <= 'z') + setRangeStart[setRangeChar++ - 'a'] = i; + } + for (setRangeChar = 'a'; setRangeChar < 'z'; setRangeChar++) + setRangeEnd[setRangeChar - 'a'] = setRangeStart[setRangeChar+1-'a'] - 1; + setRangeEnd[setRangeChar - 'a'] = i - 1; + + /* * Dump sets start/finish for the fastpath */ printf ("static const FcLangCharSetRange fcLangCharSetRanges[] = {\n"); |