- printf ("Fc Frozen Values:\n");
- printf ("\t%8s %9s %9s\n", "Type", "Count", "Bytes");
- for (t = FcTypeVoid; t <= FcTypeLangSet; t++)
- printf ("\t%8s %9d %9d\n", FcValueListFrozenName[t],
- FcValueListFrozenCount[t], FcValueListFrozenBytes[t]);
-}
-
-static FcValueListEnt *
-FcValueListEntCreate (FcValueList *h)
-{
- FcValueListAlign *ea;
- FcValueListEnt *e;
- FcValueList *l, *new;
- int n;
- int string_size = 0;
- FcChar8 *strs;
- int size;
-
- n = 0;
- for (l = h; l; l = l->next)
- {
- if (l->value.type == FcTypeString)
- string_size += strlen ((char *) l->value.u.s) + 1;
- n++;
- }
- size = sizeof (FcValueListAlign) + n * sizeof (FcValueList) + string_size;
- FcValueListFrozenCount[h->value.type]++;
- FcValueListFrozenBytes[h->value.type] += size;
- ea = malloc (size);
- if (!ea)
- return 0;
- FcMemAlloc (FC_MEM_VALLIST, size);
- e = &ea->ent;
- e->list = (FcValueList *) (ea + 1);
- strs = (FcChar8 *) (e->list + n);
- new = e->list;
- for (l = h; l; l = l->next, new++)
- {
- if (l->value.type == FcTypeString)
- {
- new->value.type = FcTypeString;
- new->value.u.s = strs;
- strcpy ((char *) strs, (char *) l->value.u.s);
- strs += strlen ((char *) strs) + 1;
- }
- else
- {
- new->value = l->value;
- new->value = FcValueSave (new->value);
- }
- new->binding = l->binding;
- if (l->next)
- new->next = new + 1;
- else
- new->next = 0;
- }
- return e;
-}
-
-static void
-FcValueListEntDestroy (FcValueListEnt *e)
-{
- FcValueList *l;
-
- FcValueListFrozenCount[e->list->value.type]--;
-
- /* XXX: We should perform these two operations with "size" as
- computed in FcValueListEntCreate, but we don't have access to
- that value here. Without this, the FcValueListFrozenBytes
- values will be wrong as will the FcMemFree counts.
-
- FcValueListFrozenBytes[e->list->value.type] -= size;
- FcMemFree (FC_MEM_VALLIST, size);
- */
-
- for (l = e->list; l; l = l->next)
- {
- if (l->value.type != FcTypeString)
- FcValueDestroy (l->value);
- }
- /* XXX: Are we being too chummy with the implementation here to
- free(e) when it was actually the enclosing FcValueListAlign
- that was allocated? */
- free (e);
-}
-
-static int FcValueListTotal;
-static int FcValueListUsed;
-
-static FcValueListEnt *FcValueListHashTable[FC_VALUE_LIST_HASH_SIZE];
-
-static FcValueList *
-FcValueListFreeze (FcValueList *l)
-{
- FcChar32 hash = FcValueListHash (l);
- FcValueListEnt **bucket = &FcValueListHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
- FcValueListEnt *ent;
-
- FcValueListTotal++;
- for (ent = *bucket; ent; ent = ent->next)
- {
- if (ent->hash == hash && FcValueListEqual (ent->list, l))
- return ent->list;
- }
-
- ent = FcValueListEntCreate (l);
- if (!ent)
- return 0;
-
- FcValueListUsed++;
- ent->hash = hash;
- ent->next = *bucket;
- *bucket = ent;
- return ent->list;
-}
-
-static void
-FcValueListThawAll (void)
-{
- int i;
- FcValueListEnt *ent, *next;
-
- for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)
- {
- for (ent = FcValueListHashTable[i]; ent; ent = next)
- {
- next = ent->next;
- FcValueListEntDestroy (ent);
- }
- FcValueListHashTable[i] = 0;
- }
-
- FcValueListTotal = 0;
- FcValueListUsed = 0;
-}
-
-static FcChar32
-FcPatternBaseHash (FcPattern *b)
-{
- FcChar32 hash = b->num;
- int i;
-
- for (i = 0; i < b->num; i++)
- hash = ((hash << 1) | (hash >> 31)) ^ ((long) b->elts[i].values);
- return hash;
-}
-
-typedef struct _FcPatternEnt FcPatternEnt;
-
-struct _FcPatternEnt {
- FcPatternEnt *next;
- FcChar32 hash;
- FcPattern pattern;
-};
-
-static int FcPatternTotal;
-static int FcPatternUsed;
-
-static FcPatternEnt *FcPatternHashTable[FC_VALUE_LIST_HASH_SIZE];
-
-static FcPattern *
-FcPatternBaseFreeze (FcPattern *b)
-{
- FcChar32 hash = FcPatternBaseHash (b);
- FcPatternEnt **bucket = &FcPatternHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
- FcPatternEnt *ent;
- int i;
- char *objects;
- int size_objects;
- int size;
-
- FcPatternTotal++;
- for (ent = *bucket; ent; ent = ent->next)
- {
- if (ent->hash == hash && b->num == ent->pattern.num)
- {
- for (i = 0; i < b->num; i++)
- {
- if (strcmp (b->elts[i].object, ent->pattern.elts[i].object))
- break;
- if (b->elts[i].values != ent->pattern.elts[i].values)
- break;
- }
- if (i == b->num)
- return &ent->pattern;
- }
- }
-
- /*
- * Compute size of pattern + elts + object names
- */
- size_objects = 0;
- for (i = 0; i < b->num; i++)
- size_objects += strlen (b->elts[i].object) + 1;
-
- size = sizeof (FcPatternEnt) + b->num*sizeof (FcPatternElt) + size_objects;
- ent = malloc (size);
- if (!ent)
- return 0;
-
- FcMemAlloc (FC_MEM_PATTERN, size);
- FcPatternUsed++;
-
- ent->pattern.elts = (FcPatternElt *) (ent + 1);
- ent->pattern.num = b->num;
- ent->pattern.size = b->num;
- ent->pattern.ref = FC_REF_CONSTANT;
-
- objects = (char *) (ent->pattern.elts + b->num);
- for (i = 0; i < b->num; i++)
- {
- ent->pattern.elts[i].values = b->elts[i].values;
- strcpy (objects, b->elts[i].object);
- ent->pattern.elts[i].object = objects;
- objects += strlen (objects) + 1;
- }
-
- ent->hash = hash;
- ent->next = *bucket;
- *bucket = ent;
- return &ent->pattern;
-}
-
-static void
-FcPatternBaseThawAll (void)
-{
- int i;
- FcPatternEnt *ent, *next;
-
- for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)