]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcpat.c
Bug 44826 - <alias> must contain only a single <family>
[fontconfig.git] / src / fcpat.c
index 9f8fe14ad867b733e8f9adba82f640c338474fb2..8f63659df673c2f204ec7bb5fe2ddeac6bff9dee 100644 (file)
@@ -1,45 +1,33 @@
 /*
- * $RCSId: xc/lib/fontconfig/src/fcpat.c,v 1.18 2002/09/18 17:11:46 tsi Exp $
- *
  * Copyright © 2000 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
  * the above copyright notice appear in all copies and that both that
  * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
+ * documentation, and that the name of the author(s) not be used in
  * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
+ * specific, written prior permission.  The authors make no
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "fcint.h"
+#include "fcftint.h"
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
-#include <sys/mman.h>
-#include "fcint.h"
-
-static FcPattern * fcpatterns = NULL;
-static int fcpattern_ptr, fcpattern_count;
-static FcPatternElt * fcpatternelts = NULL;
-static int fcpatternelt_ptr, fcpatternelt_count;
-static FcValueList * fcvaluelists = NULL;
-static int fcvaluelist_ptr, fcvaluelist_count;
 
 static FcBool
-FcPatternEltIsDynamic (FcPatternEltPtr pei);
-
-static FcPatternEltPtr
-FcPatternEltPtrCreateDynamic (FcPatternElt * e);
+FcHashOwnsName(const FcChar8 *name);
 
 FcPattern *
 FcPatternCreate (void)
@@ -52,7 +40,7 @@ FcPatternCreate (void)
     FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern));
     p->num = 0;
     p->size = 0;
-    p->elts = FcPatternEltPtrCreateDynamic(0);
+    p->elts_offset = FcPtrToOffset (p, NULL);
     p->ref = 1;
     return p;
 }
@@ -62,20 +50,47 @@ FcValueDestroy (FcValue v)
 {
     switch (v.type) {
     case FcTypeString:
-       FcObjectPtrDestroy (v.u.si);
+        if (!FcHashOwnsName(v.u.s))
+            FcStrFree ((FcChar8 *) v.u.s);
        break;
     case FcTypeMatrix:
-       FcMatrixPtrDestroy (v.u.mi);
+       FcMatrixFree ((FcMatrix *) v.u.m);
+       break;
+    case FcTypeCharSet:
+       FcCharSetDestroy ((FcCharSet *) v.u.c);
+       break;
+    case FcTypeLangSet:
+       FcLangSetDestroy ((FcLangSet *) v.u.l);
+       break;
+    default:
+       break;
+    }
+}
+
+FcValue
+FcValueCanonicalize (const FcValue *v)
+{
+    FcValue new;
+
+    switch (v->type)
+    {
+    case FcTypeString:
+       new.u.s = FcValueString(v);
+       new.type = FcTypeString;
        break;
     case FcTypeCharSet:
-       FcCharSetPtrDestroy (v.u.ci);
+       new.u.c = FcValueCharSet(v);
+       new.type = FcTypeCharSet;
        break;
     case FcTypeLangSet:
-       FcLangSetPtrDestroy (v.u.li);
+       new.u.l = FcValueLangSet(v);
+       new.type = FcTypeLangSet;
        break;
     default:
+       new = *v;
        break;
     }
+    return new;
 }
 
 FcValue
@@ -83,26 +98,23 @@ FcValueSave (FcValue v)
 {
     switch (v.type) {
     case FcTypeString:
-       v.u.si = FcObjectStaticName(FcObjectPtrU(v.u.si));
-       if (!FcObjectPtrU(v.u.si))
+       v.u.s = FcStrStaticName (v.u.s);
+       if (!v.u.s)
            v.type = FcTypeVoid;
        break;
     case FcTypeMatrix:
-       v.u.mi = FcMatrixPtrCreateDynamic
-           (FcMatrixCopy (FcMatrixPtrU(v.u.mi)));
-       if (!FcMatrixPtrU(v.u.mi))
+       v.u.m = FcMatrixCopy (v.u.m);
+       if (!v.u.m)
            v.type = FcTypeVoid;
        break;
     case FcTypeCharSet:
-       v.u.ci = FcCharSetPtrCreateDynamic
-           (FcCharSetCopy (FcCharSetPtrU(v.u.ci)));
-       if (!FcCharSetPtrU(v.u.ci))
+       v.u.c = FcCharSetCopy ((FcCharSet *) v.u.c);
+       if (!v.u.c)
            v.type = FcTypeVoid;
        break;
     case FcTypeLangSet:
-       v.u.li = FcLangSetPtrCreateDynamic
-           (FcLangSetCopy (FcLangSetPtrU(v.u.li)));
-       if (!FcLangSetPtrU(v.u.li))
+       v.u.l = FcLangSetCopy (v.u.l);
+       if (!v.u.l)
            v.type = FcTypeVoid;
        break;
     default:
@@ -115,31 +127,30 @@ void
 FcValueListDestroy (FcValueListPtr l)
 {
     FcValueListPtr next;
-    for (; FcValueListPtrU(l); l = next)
+    for (; l; l = next)
     {
-       switch (FcValueListPtrU(l)->value.type) {
+       switch (l->value.type) {
        case FcTypeString:
-           FcObjectPtrDestroy (FcValueListPtrU(l)->value.u.si);
+            if (!FcHashOwnsName((FcChar8 *)l->value.u.s))
+                FcStrFree ((FcChar8 *)l->value.u.s);
            break;
        case FcTypeMatrix:
-           FcMatrixPtrDestroy (FcValueListPtrU(l)->value.u.mi);
+           FcMatrixFree ((FcMatrix *)l->value.u.m);
            break;
        case FcTypeCharSet:
-           FcCharSetDestroy 
-               (FcCharSetPtrU (FcValueListPtrU(l)->value.u.ci));
+           FcCharSetDestroy
+               ((FcCharSet *) (l->value.u.c));
            break;
        case FcTypeLangSet:
-           FcLangSetDestroy 
-               (FcLangSetPtrU (FcValueListPtrU(l)->value.u.li));
+           FcLangSetDestroy
+               ((FcLangSet *) (l->value.u.l));
            break;
        default:
            break;
        }
-       next = FcValueListPtrU(l)->next;
-
+       next = FcValueListNext(l);
        FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
-       if (l.storage == FcStorageDynamic)
-           free(l.u.dyn);
+       free(l);
     }
 }
 
@@ -169,21 +180,17 @@ FcValueEqual (FcValue va, FcValue vb)
     case FcTypeDouble:
        return va.u.d == vb.u.d;
     case FcTypeString:
-       return FcStrCmpIgnoreCase (FcObjectPtrU(va.u.si), 
-                                  FcObjectPtrU(vb.u.si)) == 0;
+       return FcStrCmpIgnoreCase (va.u.s, vb.u.s) == 0;
     case FcTypeBool:
        return va.u.b == vb.u.b;
     case FcTypeMatrix:
-       return FcMatrixEqual (FcMatrixPtrU(va.u.mi), 
-                             FcMatrixPtrU(vb.u.mi));
+       return FcMatrixEqual (va.u.m, vb.u.m);
     case FcTypeCharSet:
-       return FcCharSetEqual (FcCharSetPtrU(va.u.ci), 
-                              FcCharSetPtrU(vb.u.ci));
+       return FcCharSetEqual (va.u.c, vb.u.c);
     case FcTypeFTFace:
        return va.u.f == vb.u.f;
     case FcTypeLangSet:
-       return FcLangSetEqual (FcLangSetPtrU(va.u.li), 
-                              FcLangSetPtrU(vb.u.li));
+       return FcLangSetEqual (va.u.l, vb.u.l);
     }
     return FcFalse;
 }
@@ -198,12 +205,12 @@ FcDoubleHash (double d)
     return (FcChar32) d;
 }
 
-static FcChar32
+FcChar32
 FcStringHash (const FcChar8 *s)
 {
     FcChar8    c;
     FcChar32   h = 0;
-    
+
     if (s)
        while ((c = *s++))
            h = ((h << 1) | (h >> 31)) ^ c;
@@ -211,34 +218,31 @@ FcStringHash (const FcChar8 *s)
 }
 
 static FcChar32
-FcValueHash (FcValue v)
+FcValueHash (const FcValue *v)
 {
-    switch (v.type) {
+    switch (v->type) {
     case FcTypeVoid:
        return 0;
     case FcTypeInteger:
-       return (FcChar32) v.u.i;
+       return (FcChar32) v->u.i;
     case FcTypeDouble:
-       return FcDoubleHash (v.u.d);
+       return FcDoubleHash (v->u.d);
     case FcTypeString:
-       return FcStringHash (FcObjectPtrU(v.u.si));
+       return FcStringHash (FcValueString(v));
     case FcTypeBool:
-       return (FcChar32) v.u.b;
+       return (FcChar32) v->u.b;
     case FcTypeMatrix:
-    {
-       FcMatrix * m = FcMatrixPtrU(v.u.mi);
-       return (FcDoubleHash (m->xx) ^ 
-               FcDoubleHash (m->xy) ^ 
-               FcDoubleHash (m->yx) ^ 
-               FcDoubleHash (m->yy));
-    }
+       return (FcDoubleHash (v->u.m->xx) ^
+               FcDoubleHash (v->u.m->xy) ^
+               FcDoubleHash (v->u.m->yx) ^
+               FcDoubleHash (v->u.m->yy));
     case FcTypeCharSet:
-       return (FcChar32) (FcCharSetPtrU(v.u.ci))->num;
+       return (FcChar32) FcValueCharSet(v)->num;
     case FcTypeFTFace:
-       return FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->family_name) ^
-              FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->style_name);
+       return FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->family_name) ^
+              FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->style_name);
     case FcTypeLangSet:
-       return FcLangSetHash (FcLangSetPtrU(v.u.li));
+       return FcLangSetHash (FcValueLangSet(v));
     }
     return FcFalse;
 }
@@ -246,18 +250,17 @@ FcValueHash (FcValue v)
 static FcBool
 FcValueListEqual (FcValueListPtr la, FcValueListPtr lb)
 {
-    if (FcValueListPtrU(la) == FcValueListPtrU(lb))
+    if (la == lb)
        return FcTrue;
 
-    while (FcValueListPtrU(la) && FcValueListPtrU(lb))
+    while (la && lb)
     {
-       if (!FcValueEqual (FcValueListPtrU(la)->value, 
-                          FcValueListPtrU(lb)->value))
+       if (!FcValueEqual (la->value, lb->value))
            return FcFalse;
-       la = FcValueListPtrU(la)->next;
-       lb = FcValueListPtrU(lb)->next;
+       la = FcValueListNext(la);
+       lb = FcValueListNext(lb);
     }
-    if (FcValueListPtrU(la) || FcValueListPtrU(lb))
+    if (la || lb)
        return FcFalse;
     return FcTrue;
 }
@@ -266,12 +269,10 @@ static FcChar32
 FcValueListHash (FcValueListPtr l)
 {
     FcChar32   hash = 0;
-    
-    while (FcValueListPtrU(l))
+
+    for (; l; l = FcValueListNext(l))
     {
-       hash = ((hash << 1) | (hash >> 31)) ^ 
-           FcValueHash (FcValueListPtrU(l)->value);
-       l = FcValueListPtrU(l)->next;
+       hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (&l->value);
     }
     return hash;
 }
@@ -280,391 +281,33 @@ void
 FcPatternDestroy (FcPattern *p)
 {
     int                    i;
-    
-    if (p->ref == FC_REF_CONSTANT || --p->ref > 0)
-       return;
-
-    for (i = 0; i < p->num; i++)
-       FcValueListDestroy ((FcPatternEltU(p->elts)+i)->values);
-
-    p->num = 0;
-    if (FcPatternEltU(p->elts) && FcPatternEltIsDynamic(p->elts))
-    {
-       FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
-       free (FcPatternEltU(p->elts));
-       p->elts = FcPatternEltPtrCreateDynamic(0);
-    }
-    p->size = 0;
-    FcMemFree (FC_MEM_PATTERN, sizeof (FcPattern));
-    free (p);
-}
-
-#define FC_VALUE_LIST_HASH_SIZE            257
-#define FC_PATTERN_HASH_SIZE       67
-
-typedef struct _FcValueListEnt FcValueListEnt;
-
-struct _FcValueListEnt {
-    FcValueListEnt  *next;
-    FcValueListPtr  list;
-    FcChar32       hash, pad;
-};
-
-typedef union _FcValueListAlign {
-    FcValueListEnt  ent;
-    FcValueList            list;
-} FcValueListAlign;
-
-static int         FcValueListFrozenCount[FcTypeLangSet + 1];
-static int         FcValueListFrozenBytes[FcTypeLangSet + 1];
-static char        *FcValueListFrozenName[] = {
-    "Void", 
-    "Integer", 
-    "Double", 
-    "String", 
-    "Bool",
-    "Matrix",
-    "CharSet",
-    "FTFace",
-    "LangSet"
-};
-
-void
-FcValueListReport (void);
-    
-void
-FcValueListReport (void)
-{
-    FcType  t;
-
-    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 (FcValueListPtr h)
-{
-    FcValueListAlign   *ea;
-    FcValueListEnt  *e;
-    FcValueListPtr  l;
-    FcValueList     *new;
-    int                    n;
-    int                    size;
-
-    n = 0;
-    for (l = h; FcValueListPtrU(l); l = FcValueListPtrU(l)->next)
-       n++;
-    size = sizeof (FcValueListAlign) + n * sizeof (FcValueList);
-    FcValueListFrozenCount[FcValueListPtrU(h)->value.type]++;
-    FcValueListFrozenBytes[FcValueListPtrU(h)->value.type] += size;
-    // this leaks for some reason
-    ea = malloc (sizeof (FcValueListAlign));
-    if (!ea)
-       return 0;
-    new = malloc (n * sizeof (FcValueList));
-    if (!new)
-        return 0;
-    memset(new, 0, n * sizeof (FcValueList));
-    FcMemAlloc (FC_MEM_VALLIST, size);
-    e = &ea->ent;
-    e->list = (FcValueListPtr) FcValueListPtrCreateDynamic(new);
-    for (l = h; FcValueListPtrU(l); 
-        l = FcValueListPtrU(l)->next, new++)
-    {
-       if (FcValueListPtrU(l)->value.type == FcTypeString)
-       {
-           new->value.type = FcTypeString;
-           new->value.u.si = FcObjectStaticName
-               (FcObjectPtrU(FcValueListPtrU(l)->value.u.si));
-       }
-       else
-       {
-           new->value = FcValueSave (FcValueListPtrU(l)->value);
-       }
-       new->binding = FcValueListPtrU(l)->binding;
-       if (FcValueListPtrU(FcValueListPtrU(l)->next))
-       {
-           new->next = FcValueListPtrCreateDynamic(new + 1);
-       }
-       else
-       {
-           new->next = FcValueListPtrCreateDynamic(0);
-       }
-    }
-    return e;
-}
-
-static void
-FcValueListEntDestroy (FcValueListEnt *e)
-{
-    FcValueListPtr     l;
-
-    FcValueListFrozenCount[FcValueListPtrU(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; FcValueListPtrU(l); 
-        l = FcValueListPtrU(l)->next)
-    {
-       if (FcValueListPtrU(l)->value.type != FcTypeString)
-           FcValueDestroy (FcValueListPtrU(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 FcValueListPtr
-FcValueListFreeze (FcValueListPtr 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 FcValueListPtrCreateDynamic(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) (FcValueListPtrU((FcPatternEltU(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)
-{
-    FcPattern           *ep;
-    FcPatternElt       *epp;
-    FcChar32           hash = FcPatternBaseHash (b);
-    FcPatternEnt       **bucket = &FcPatternHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
-    FcPatternEnt       *ent;
-    int                        i;
-
-    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 (FcObjectPtrCompare((FcPatternEltU(b->elts)+i)->object,
-                                      (FcPatternEltU(ent->pattern->elts)+i)->object) != 0)
-                   break;
-               if (FcValueListPtrU((FcPatternEltU(b->elts)+i)->values) != 
-                    FcValueListPtrU((FcPatternEltU(ent->pattern->elts)+i)->values))
-                   break;
-           }
-           if (i == b->num)
-               return ent->pattern;
-       }
-    }
-
-    /*
-     * Compute size of pattern + elts
-     */
-    ent = malloc (sizeof (FcPatternEnt));
-    if (!ent)
-       return 0;
-
-    FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPatternEnt));
-    FcPatternUsed++;
-
-    ep = FcPatternCreate();
-    if (!ep)
-        return 0;
-    ent->pattern = ep;
-    epp = malloc(b->num * sizeof (FcPatternElt));
-    if (!epp)
-        goto bail;
-    ep->elts = FcPatternEltPtrCreateDynamic(epp);
-
-    FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt)*(b->num));
-
-    ep->num = b->num;
-    ep->size = b->num;
-    ep->ref = FC_REF_CONSTANT;
-
-    for (i = 0; i < b->num; i++)
-    {
-       (FcPatternEltU(ep->elts)+i)->values = 
-           (FcPatternEltU(b->elts)+i)->values;
-       (FcPatternEltU(ep->elts)+i)->object = 
-           (FcPatternEltU(b->elts)+i)->object;
-    }
-
-    ent->hash = hash;
-    ent->next = *bucket;
-    *bucket = ent;
-    return ent->pattern;
- bail:
-    free(ent);
-    FcMemFree (FC_MEM_PATTERN, sizeof (FcPatternEnt));
-    FcPatternUsed--;
-    return 0;
-}
-
-static void
-FcPatternBaseThawAll (void)
-{
-    int i;
-    FcPatternEnt       *ent, *next;
+    FcPatternElt    *elts;
 
-    for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)
+    if (p->ref == FC_REF_CONSTANT)
     {
-       for (ent = FcPatternHashTable[i]; ent; ent = next)
-       {
-           next = ent->next;
-           free (ent);
-       }
-       FcPatternHashTable[i] = 0;
+       FcCacheObjectDereference (p);
+       return;
     }
+       
+    if (--p->ref > 0)
+       return;
 
-    FcPatternTotal = 0;
-    FcPatternUsed = 0;
-}
-
-FcPattern *
-FcPatternFreeze (FcPattern *p)
-{
-    FcPattern  *b, *n = 0;
-    FcPatternElt *e;
-    int                i;
-    
-    if (p->ref == FC_REF_CONSTANT)
-       return p;
-
-    b = FcPatternCreate();
-    if (!b)
-        return 0;
-
-    b->num = p->num;
-    b->size = b->num;
-    b->ref = 1;
-
-    e = malloc(b->num * sizeof (FcPatternElt));
-    if (!e)
-        return 0;
-    b->elts = FcPatternEltPtrCreateDynamic(e);
-    FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt)*(b->num));
-
-    /*
-     * Freeze object lists
-     */
+    elts = FcPatternElts (p);
     for (i = 0; i < p->num; i++)
-    {
-       (FcPatternEltU(b->elts)+i)->object = 
-           (FcPatternEltU(p->elts)+i)->object;
-       (FcPatternEltU(b->elts)+i)->values = 
-           FcValueListFreeze((FcPatternEltU(p->elts)+i)->values);
-       if (!FcValueListPtrU((FcPatternEltU(p->elts)+i)->values))
-           goto bail;
-    }
-    /*
-     * Freeze base
-     */
-    n = FcPatternBaseFreeze (b);
-#ifdef CHATTY
-    if (FcDebug() & FC_DBG_MEMORY)
-    {
-       printf ("ValueLists: total %9d used %9d\n", FcValueListTotal, FcValueListUsed);
-       printf ("Patterns:   total %9d used %9d\n", FcPatternTotal, FcPatternUsed);
-    }
-#endif
- bail:
-    free(FcPatternEltU(b->elts));
-    b->elts = FcPatternEltPtrCreateDynamic(0);
-    FcMemFree (FC_MEM_PATELT, sizeof (FcPatternElt)*(b->num));
-    b->num = -1;
-#ifdef DEBUG
-    assert (FcPatternEqual (n, p));
-#endif
-    return n;
-}
+       FcValueListDestroy (FcPatternEltValues(&elts[i]));
 
-void
-FcPatternThawAll (void)
-{
-    FcPatternBaseThawAll ();
-    FcValueListThawAll ();
+    FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
+    free (elts);
+    FcMemFree (FC_MEM_PATTERN, sizeof (FcPattern));
+    free (p);
 }
 
 static int
-FcPatternPosition (const FcPattern *p, const char *object)
+FcPatternObjectPosition (const FcPattern *p, FcObject object)
 {
     int            low, high, mid, c;
-    FcObjectPtr obj;
+    FcPatternElt    *elts = FcPatternElts(p);
 
-    obj = FcObjectStaticName(object);
     low = 0;
     high = p->num - 1;
     c = 1;
@@ -672,7 +315,7 @@ FcPatternPosition (const FcPattern *p, const char *object)
     while (low <= high)
     {
        mid = (low + high) >> 1;
-       c = FcObjectPtrCompare((FcPatternEltU(p->elts)+mid)->object, obj);
+       c = elts[mid].object - object;
        if (c == 0)
            return mid;
        if (c < 0)
@@ -686,32 +329,32 @@ FcPatternPosition (const FcPattern *p, const char *object)
 }
 
 FcPatternElt *
-FcPatternFindElt (const FcPattern *p, const char *object)
+FcPatternObjectFindElt (const FcPattern *p, FcObject object)
 {
-    int            i = FcPatternPosition (p, object);
+    int            i = FcPatternObjectPosition (p, object);
     if (i < 0)
        return 0;
-    return FcPatternEltU(p->elts)+i;
+    return &FcPatternElts(p)[i];
 }
 
 FcPatternElt *
-FcPatternInsertElt (FcPattern *p, const char *object)
+FcPatternObjectInsertElt (FcPattern *p, FcObject object)
 {
     int                    i;
     FcPatternElt   *e;
-    
-    i = FcPatternPosition (p, object);
+
+    i = FcPatternObjectPosition (p, object);
     if (i < 0)
     {
        i = -i - 1;
-    
+
        /* reallocate array */
        if (p->num + 1 >= p->size)
        {
            int s = p->size + 16;
-           if (FcPatternEltU(p->elts))
+           if (p->size)
            {
-               FcPatternElt *e0 = FcPatternEltU(p->elts);
+               FcPatternElt *e0 = FcPatternElts(p);
                e = (FcPatternElt *) realloc (e0, s * sizeof (FcPatternElt));
                if (!e) /* maybe it was mmapped */
                {
@@ -724,52 +367,54 @@ FcPatternInsertElt (FcPattern *p, const char *object)
                e = (FcPatternElt *) malloc (s * sizeof (FcPatternElt));
            if (!e)
                return FcFalse;
-           p->elts = FcPatternEltPtrCreateDynamic(e);
+           p->elts_offset = FcPtrToOffset (p, e);
            if (p->size)
                FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
            FcMemAlloc (FC_MEM_PATELT, s * sizeof (FcPatternElt));
            while (p->size < s)
            {
-               (FcPatternEltU(p->elts)+p->size)->object = 0;
-               (FcPatternEltU(p->elts)+p->size)->values = 
-                   FcValueListPtrCreateDynamic(0);
+               e[p->size].object = 0;
+               e[p->size].values = NULL;
                p->size++;
            }
        }
        
+       e = FcPatternElts(p);
        /* move elts up */
-       memmove (FcPatternEltU(p->elts) + i + 1,
-                FcPatternEltU(p->elts) + i,
+       memmove (e + i + 1,
+                e + i,
                 sizeof (FcPatternElt) *
                 (p->num - i));
-                
+               
        /* bump count */
        p->num++;
        
-       (FcPatternEltU(p->elts)+i)->object = FcObjectStaticName (object);
-       (FcPatternEltU(p->elts)+i)->values = FcValueListPtrCreateDynamic(0);
+       e[i].object = object;
+       e[i].values = NULL;
     }
-    
-    return FcPatternEltU(p->elts)+i;
+
+    return FcPatternElts(p) + i;
 }
 
 FcBool
 FcPatternEqual (const FcPattern *pa, const FcPattern *pb)
 {
     int        i;
+    FcPatternElt   *pae, *pbe;
 
     if (pa == pb)
        return FcTrue;
 
     if (pa->num != pb->num)
        return FcFalse;
+    pae = FcPatternElts(pa);
+    pbe = FcPatternElts(pb);
     for (i = 0; i < pa->num; i++)
     {
-       if (FcObjectPtrCompare((FcPatternEltU(pa->elts)+i)->object,
-                              (FcPatternEltU(pb->elts)+i)->object) != 0)
+       if (pae[i].object != pbe[i].object)
            return FcFalse;
-       if (!FcValueListEqual ((FcPatternEltU(pa->elts)+i)->values, 
-                              (FcPatternEltU(pb->elts)+i)->values))
+       if (!FcValueListEqual (FcPatternEltValues(&pae[i]),
+                              FcPatternEltValues(&pbe[i])))
            return FcFalse;
     }
     return FcTrue;
@@ -780,12 +425,13 @@ FcPatternHash (const FcPattern *p)
 {
     int                i;
     FcChar32   h = 0;
+    FcPatternElt    *pe = FcPatternElts(p);
 
     for (i = 0; i < p->num; i++)
     {
-       h = (((h << 1) | (h >> 31)) ^ 
-            FcStringHash ((const FcChar8 *) FcObjectPtrU(((FcPatternEltU(p->elts)+i)->object))) ^
-            FcValueListHash ((FcPatternEltU(p->elts)+i)->values));
+       h = (((h << 1) | (h >> 31)) ^
+            pe[i].object ^
+            FcValueListHash (FcPatternEltValues(&pe[i])));
     }
     return h;
 }
@@ -795,16 +441,17 @@ FcPatternEqualSubset (const FcPattern *pai, const FcPattern *pbi, const FcObject
 {
     FcPatternElt    *ea, *eb;
     int                    i;
-    
+
     for (i = 0; i < os->nobject; i++)
     {
-       ea = FcPatternFindElt (pai, FcObjectPtrU(os->objects[i]));
-       eb = FcPatternFindElt (pbi, FcObjectPtrU(os->objects[i]));
+       FcObject    object = FcObjectFromName (os->objects[i]);
+       ea = FcPatternObjectFindElt (pai, object);
+       eb = FcPatternObjectFindElt (pbi, object);
        if (ea)
        {
            if (!eb)
                return FcFalse;
-           if (!FcValueListEqual (ea->values, eb->values))
+           if (!FcValueListEqual (FcPatternEltValues(ea), FcPatternEltValues(eb)))
                return FcFalse;
        }
        else
@@ -817,130 +464,140 @@ FcPatternEqualSubset (const FcPattern *pai, const FcPattern *pbi, const FcObject
 }
 
 FcBool
-FcPatternAddWithBinding  (FcPattern        *p,
-                         const char        *object,
-                         FcValue           value,
-                         FcValueBinding    binding,
-                         FcBool            append)
+FcPatternObjectAddWithBinding  (FcPattern      *p,
+                               FcObject        object,
+                               FcValue         value,
+                               FcValueBinding  binding,
+                               FcBool          append)
 {
     FcPatternElt   *e;
     FcValueListPtr new, *prev;
-    FcValueList *  newp;
 
     if (p->ref == FC_REF_CONSTANT)
        goto bail0;
 
-    newp = malloc (sizeof (FcValueList));
-    if (!newp)
+    new = malloc (sizeof (FcValueList));
+    if (!new)
        goto bail0;
 
-    memset(newp, 0, sizeof (FcValueList));
-    new = FcValueListPtrCreateDynamic(newp);
+    memset(new, 0, sizeof (FcValueList));
     FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList));
-    /* dup string */
     value = FcValueSave (value);
     if (value.type == FcTypeVoid)
        goto bail1;
 
-    FcValueListPtrU(new)->value = value;
-    FcValueListPtrU(new)->binding = binding;
-    FcValueListPtrU(new)->next = FcValueListPtrCreateDynamic(0);
-    
-    e = FcPatternInsertElt (p, object);
+    /*
+     * Make sure the stored type is valid for built-in objects
+     */
+    if (!FcObjectValidType (object, value.type))
+    {
+       if (FcDebug() & FC_DBG_OBJTYPES)
+       {
+           printf ("FcPattern object %s does not accept value ",
+                   FcObjectName (object));
+           FcValuePrint (value);
+       }
+       goto bail1;
+    }
+
+    new->value = value;
+    new->binding = binding;
+    new->next = NULL;
+
+    e = FcPatternObjectInsertElt (p, object);
     if (!e)
        goto bail2;
-    
+
     if (append)
     {
-       for (prev = &e->values; FcValueListPtrU(*prev); prev = &FcValueListPtrU(*prev)->next)
+       for (prev = &e->values; *prev; prev = &(*prev)->next)
            ;
        *prev = new;
     }
     else
     {
-       FcValueListPtrU(new)->next = e->values;
+       new->next = e->values;
        e->values = new;
     }
-    
+
     return FcTrue;
 
-bail2:    
-    switch (value.type) {
-    case FcTypeString:
-       FcStrFree ((FcChar8 *) FcObjectPtrU(value.u.si));
-       break;
-    case FcTypeMatrix:
-       FcMatrixFree (FcMatrixPtrU(value.u.mi));
-       break;
-    case FcTypeCharSet:
-       FcCharSetDestroy (FcCharSetPtrU(value.u.ci));
-       break;
-    case FcTypeLangSet:
-       FcLangSetDestroy (FcLangSetPtrU(value.u.li));
-       break;
-    default:
-       break;
-    }
+bail2:
+    FcValueDestroy (value);
 bail1:
     FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
-    free (FcValueListPtrU(new));
+    free (new);
 bail0:
     return FcFalse;
 }
 
+FcBool
+FcPatternObjectAdd (FcPattern *p, FcObject object, FcValue value, FcBool append)
+{
+    return FcPatternObjectAddWithBinding (p, object,
+                                         value, FcValueBindingStrong, append);
+}
+
 FcBool
 FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
 {
-    return FcPatternAddWithBinding (p, object, value, FcValueBindingStrong, append);
+    return FcPatternObjectAddWithBinding (p, FcObjectFromName (object),
+                                         value, FcValueBindingStrong, append);
 }
 
 FcBool
 FcPatternAddWeak  (FcPattern *p, const char *object, FcValue value, FcBool append)
 {
-    return FcPatternAddWithBinding (p, object, value, FcValueBindingWeak, append);
+    return FcPatternObjectAddWithBinding (p, FcObjectFromName (object),
+                                         value, FcValueBindingWeak, append);
 }
 
 FcBool
-FcPatternDel (FcPattern *p, const char *object)
+FcPatternObjectDel (FcPattern *p, FcObject object)
 {
     FcPatternElt   *e;
 
-    e = FcPatternFindElt (p, object);
+    e = FcPatternObjectFindElt (p, object);
     if (!e)
        return FcFalse;
 
     /* destroy value */
     FcValueListDestroy (e->values);
-    
+
     /* shuffle existing ones down */
-    memmove (e, e+1, 
-            (FcPatternEltU(p->elts) + p->num - (e + 1)) * 
+    memmove (e, e+1,
+            (FcPatternElts(p) + p->num - (e + 1)) *
             sizeof (FcPatternElt));
     p->num--;
-    (FcPatternEltU(p->elts)+p->num)->object = 0;
-    (FcPatternEltU(p->elts)+p->num)->values = FcValueListPtrCreateDynamic(0);
+    e = FcPatternElts(p) + p->num;
+    e->object = 0;
+    e->values = NULL;
     return FcTrue;
 }
 
+FcBool
+FcPatternDel (FcPattern *p, const char *object)
+{
+    return FcPatternObjectDel (p, FcObjectFromName (object));
+}
+
 FcBool
 FcPatternRemove (FcPattern *p, const char *object, int id)
 {
     FcPatternElt    *e;
     FcValueListPtr  *prev, l;
 
-    e = FcPatternFindElt (p, object);
+    e = FcPatternObjectFindElt (p, FcObjectFromName (object));
     if (!e)
        return FcFalse;
-    for (prev = &e->values; 
-        FcValueListPtrU(l = *prev); 
-        prev = &FcValueListPtrU(l)->next)
+    for (prev = &e->values; (l = *prev); prev = &l->next)
     {
        if (!id)
        {
-           *prev = FcValueListPtrU(l)->next;
-           FcValueListPtrU(l)->next = FcValueListPtrCreateDynamic(0);
+           *prev = l->next;
+           l->next = NULL;
            FcValueListDestroy (l);
-           if (!FcValueListPtrU(e->values))
+           if (!e->values)
                FcPatternDel (p, object);
            return FcTrue;
        }
@@ -950,34 +607,59 @@ FcPatternRemove (FcPattern *p, const char *object, int id)
 }
 
 FcBool
-FcPatternAddInteger (FcPattern *p, const char *object, int i)
+FcPatternObjectAddInteger (FcPattern *p, FcObject object, int i)
 {
     FcValue    v;
 
     v.type = FcTypeInteger;
     v.u.i = i;
-    return FcPatternAdd (p, object, v, FcTrue);
+    return FcPatternObjectAdd (p, object, v, FcTrue);
 }
 
 FcBool
-FcPatternAddDouble (FcPattern *p, const char *object, double d)
+FcPatternAddInteger (FcPattern *p, const char *object, int i)
+{
+    return FcPatternObjectAddInteger (p, FcObjectFromName (object), i);
+}
+
+FcBool
+FcPatternObjectAddDouble (FcPattern *p, FcObject object, double d)
 {
     FcValue    v;
 
     v.type = FcTypeDouble;
     v.u.d = d;
-    return FcPatternAdd (p, object, v, FcTrue);
+    return FcPatternObjectAdd (p, object, v, FcTrue);
 }
 
 
 FcBool
-FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s)
+FcPatternAddDouble (FcPattern *p, const char *object, double d)
+{
+    return FcPatternObjectAddDouble (p, FcObjectFromName (object), d);
+}
+
+FcBool
+FcPatternObjectAddString (FcPattern *p, FcObject object, const FcChar8 *s)
 {
     FcValue    v;
 
+    if (!s)
+    {
+       v.type = FcTypeVoid;
+       v.u.s = 0;
+       return FcPatternObjectAdd (p, object, v, FcTrue);
+    }
+
     v.type = FcTypeString;
-    v.u.si = FcObjectStaticName(s);
-    return FcPatternAdd (p, object, v, FcTrue);
+    v.u.s = FcStrStaticName(s);
+    return FcPatternObjectAdd (p, object, v, FcTrue);
+}
+
+FcBool
+FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s)
+{
+    return FcPatternObjectAddString (p, FcObjectFromName (object), s);
 }
 
 FcBool
@@ -986,19 +668,25 @@ FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s)
     FcValue    v;
 
     v.type = FcTypeMatrix;
-    v.u.mi = FcMatrixPtrCreateDynamic((FcMatrix *) s);
+    v.u.m = s;
     return FcPatternAdd (p, object, v, FcTrue);
 }
 
 
 FcBool
-FcPatternAddBool (FcPattern *p, const char *object, FcBool b)
+FcPatternObjectAddBool (FcPattern *p, FcObject object, FcBool b)
 {
     FcValue    v;
 
     v.type = FcTypeBool;
     v.u.b = b;
-    return FcPatternAdd (p, object, v, FcTrue);
+    return FcPatternObjectAdd (p, object, v, FcTrue);
+}
+
+FcBool
+FcPatternAddBool (FcPattern *p, const char *object, FcBool b)
+{
+    return FcPatternObjectAddBool (p, FcObjectFromName (object), b);
 }
 
 FcBool
@@ -1007,7 +695,7 @@ FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c)
     FcValue    v;
 
     v.type = FcTypeCharSet;
-    v.u.ci = FcCharSetPtrCreateDynamic((FcCharSet *)c);
+    v.u.c = (FcCharSet *)c;
     return FcPatternAdd (p, object, v, FcTrue);
 }
 
@@ -1027,24 +715,24 @@ FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls)
     FcValue    v;
 
     v.type = FcTypeLangSet;
-    v.u.li = FcLangSetPtrCreateDynamic((FcLangSet *)ls);
+    v.u.l = (FcLangSet *)ls;
     return FcPatternAdd (p, object, v, FcTrue);
 }
 
 FcResult
-FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v)
+FcPatternObjectGet (const FcPattern *p, FcObject object, int id, FcValue *v)
 {
     FcPatternElt   *e;
     FcValueListPtr l;
 
-    e = FcPatternFindElt (p, object);
+    e = FcPatternObjectFindElt (p, object);
     if (!e)
        return FcResultNoMatch;
-    for (l = e->values; FcValueListPtrU(l); l = FcValueListPtrU(l)->next)
+    for (l = FcPatternEltValues(e); l; l = FcValueListNext(l))
     {
        if (!id)
        {
-           *v = FcValueListPtrU(l)->value;
+           *v = FcValueCanonicalize(&l->value);
            return FcResultMatch;
        }
        id--;
@@ -1053,12 +741,18 @@ FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v)
 }
 
 FcResult
-FcPatternGetInteger (const FcPattern *p, const char *object, int id, int *i)
+FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v)
+{
+    return FcPatternObjectGet (p, FcObjectFromName (object), id, v);
+}
+
+FcResult
+FcPatternObjectGetInteger (const FcPattern *p, FcObject object, int id, int *i)
 {
     FcValue    v;
     FcResult   r;
 
-    r = FcPatternGet (p, object, id, &v);
+    r = FcPatternObjectGet (p, object, id, &v);
     if (r != FcResultMatch)
        return r;
     switch (v.type) {
@@ -1075,12 +769,19 @@ FcPatternGetInteger (const FcPattern *p, const char *object, int id, int *i)
 }
 
 FcResult
-FcPatternGetDouble (const FcPattern *p, const char *object, int id, double *d)
+FcPatternGetInteger (const FcPattern *p, const char *object, int id, int *i)
+{
+    return FcPatternObjectGetInteger (p, FcObjectFromName (object), id, i);
+}
+
+
+FcResult
+FcPatternObjectGetDouble (const FcPattern *p, FcObject object, int id, double *d)
 {
     FcValue    v;
     FcResult   r;
 
-    r = FcPatternGet (p, object, id, &v);
+    r = FcPatternObjectGet (p, object, id, &v);
     if (r != FcResultMatch)
        return r;
     switch (v.type) {
@@ -1097,20 +798,33 @@ FcPatternGetDouble (const FcPattern *p, const char *object, int id, double *d)
 }
 
 FcResult
-FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s)
+FcPatternGetDouble (const FcPattern *p, const char *object, int id, double *d)
+{
+    return FcPatternObjectGetDouble (p, FcObjectFromName (object), id, d);
+}
+
+FcResult
+FcPatternObjectGetString (const FcPattern *p, FcObject object, int id, FcChar8 ** s)
 {
     FcValue    v;
     FcResult   r;
 
-    r = FcPatternGet (p, object, id, &v);
+    r = FcPatternObjectGet (p, object, id, &v);
     if (r != FcResultMatch)
        return r;
     if (v.type != FcTypeString)
         return FcResultTypeMismatch;
-    *s = (FcChar8 *) FcObjectPtrU(v.u.si);
+
+    *s = (FcChar8 *) v.u.s;
     return FcResultMatch;
 }
 
+FcResult
+FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s)
+{
+    return FcPatternObjectGetString (p, FcObjectFromName (object), id, s);
+}
+
 FcResult
 FcPatternGetMatrix(const FcPattern *p, const char *object, int id, FcMatrix **m)
 {
@@ -1122,7 +836,7 @@ FcPatternGetMatrix(const FcPattern *p, const char *object, int id, FcMatrix **m)
        return r;
     if (v.type != FcTypeMatrix)
         return FcResultTypeMismatch;
-    *m = FcMatrixPtrU(v.u.mi);
+    *m = (FcMatrix *)v.u.m;
     return FcResultMatch;
 }
 
@@ -1153,7 +867,7 @@ FcPatternGetCharSet(const FcPattern *p, const char *object, int id, FcCharSet **
        return r;
     if (v.type != FcTypeCharSet)
         return FcResultTypeMismatch;
-    *c = FcCharSetPtrU(v.u.ci);
+    *c = (FcCharSet *)v.u.c;
     return FcResultMatch;
 }
 
@@ -1183,7 +897,7 @@ FcPatternGetLangSet(const FcPattern *p, const char *object, int id, FcLangSet **
        return r;
     if (v.type != FcTypeLangSet)
         return FcResultTypeMismatch;
-    *ls = FcLangSetPtrU(v.u.li);
+    *ls = (FcLangSet *)v.u.l;
     return FcResultMatch;
 }
 
@@ -1199,16 +913,19 @@ FcPatternDuplicate (const FcPattern *orig)
     if (!new)
        goto bail0;
 
-    e = FcPatternEltU(orig->elts);
+    e = FcPatternElts(orig);
 
     for (i = 0; i < orig->num; i++)
     {
-       for (l = (e + i)->values; 
-            FcValueListPtrU(l); 
-            l = FcValueListPtrU(l)->next)
-           if (!FcPatternAdd (new, FcObjectPtrU((e + i)->object), 
-                               FcValueListPtrU(l)->value, FcTrue))
+       for (l = FcPatternEltValues(e + i); l; l = FcValueListNext(l))
+       {
+           if (!FcPatternObjectAddWithBinding (new, e[i].object,
+                                               FcValueCanonicalize(&l->value),
+                                               l->binding,
+                                               FcTrue))
                goto bail1;
+       
+       }
     }
 
     return new;
@@ -1224,26 +941,28 @@ FcPatternReference (FcPattern *p)
 {
     if (p->ref != FC_REF_CONSTANT)
        p->ref++;
+    else
+       FcCacheObjectReference (p);
 }
 
 FcPattern *
-FcPatternVaBuild (FcPattern *orig, va_list va)
+FcPatternVaBuild (FcPattern *p, va_list va)
 {
     FcPattern  *ret;
-    
-    FcPatternVapBuild (ret, orig, va);
+
+    FcPatternVapBuild (ret, p, va);
     return ret;
 }
 
 FcPattern *
-FcPatternBuild (FcPattern *orig, ...)
+FcPatternBuild (FcPattern *p, ...)
 {
     va_list    va;
-    
-    va_start (va, orig);
-    FcPatternVapBuild (orig, orig, va);
+
+    va_start (va, p);
+    FcPatternVapBuild (p, p, va);
     va_end (va);
-    return orig;
+    return p;
 }
 
 /*
@@ -1255,696 +974,294 @@ FcPatternAppend (FcPattern *p, FcPattern *s)
     int                    i;
     FcPatternElt    *e;
     FcValueListPtr  v;
-    
+
     for (i = 0; i < s->num; i++)
     {
-       e = FcPatternEltU(s->elts)+i;
-       for (v = e->values; FcValueListPtrU(v); 
-            v = FcValueListPtrU(v)->next)
+       e = FcPatternElts(s)+i;
+       for (v = FcPatternEltValues(e); v; v = FcValueListNext(v))
        {
-           if (!FcPatternAddWithBinding (p, FcObjectPtrU(e->object),
-                                         FcValueListPtrU(v)->value, 
-                                         FcValueListPtrU(v)->binding, FcTrue))
+           if (!FcPatternObjectAddWithBinding (p, e->object,
+                                               FcValueCanonicalize(&v->value),
+                                               v->binding, FcTrue))
                return FcFalse;
        }
     }
     return FcTrue;
 }
 
-FcPatternElt *
-FcPatternEltU (FcPatternEltPtr pei)
-{
-    switch (pei.storage)
-    {
-    case FcStorageStatic:
-       if (pei.u.stat == 0) return 0;
-        return &fcpatternelts[pei.u.stat];
-    case FcStorageDynamic:
-        return pei.u.dyn;
-    default:
-       return 0;
-    }
-}
-
-static FcPatternEltPtr
-FcPatternEltPtrCreateDynamic (FcPatternElt * e)
-{
-    FcPatternEltPtr new;
-    new.storage = FcStorageDynamic;
-    new.u.dyn = e;
-    return new;
-}
-
-static FcPatternEltPtr
-FcPatternEltPtrCreateStatic (int i)
-{
-    FcPatternEltPtr new;
-    new.storage = FcStorageStatic;
-    new.u.stat = i;
-    return new;
-}
-
-static FcBool
-FcPatternEltIsDynamic (FcPatternEltPtr pei)
-{
-    return pei.storage == FcStorageDynamic;
-}
-
-
-void
-FcPatternClearStatic (void)
-{
-    fcpatterns = 0;
-    fcpattern_ptr = 0;
-    fcpattern_count = 0;
-
-    fcpatternelts = 0;
-    fcpatternelt_ptr = 0;
-    fcpatternelt_count = 0;
-}
-
-void
-FcValueListClearStatic (void)
-{
-    fcvaluelists = 0;
-    fcvaluelist_ptr = 0;
-    fcvaluelist_count = 0;
-}
-
-static FcObjectPtr
-FcObjectSerialize (FcObjectPtr si);
-
-FcBool
-FcPatternPrepareSerialize (FcPattern * p)
-{
-    int i;
-
-    fcpattern_count++;
-    fcpatternelt_count += p->num;
-
-    for (i = 0; i < p->num; i++)
-    {
-       FcObjectPrepareSerialize 
-           ((FcPatternEltU(p->elts)+i)->object);
-       if (!FcValueListPrepareSerialize 
-           (FcValueListPtrU(((FcPatternEltU(p->elts)+i)->values))))
-           return FcFalse;
-    }
-
-    return FcTrue;
-}
-
-FcBool
-FcValueListPrepareSerialize (FcValueList *p)
-{
-    FcValueList *vl;
-
-    for (vl = p;
-        vl; 
-        vl = FcValueListPtrU(vl->next))
-    {
-       FcValue v = vl->value;
-
-       switch (v.type)
-       {
-       case FcTypeMatrix:
-           FcMatrixPrepareSerialize(FcMatrixPtrU(v.u.mi));
-           break;
-       case FcTypeCharSet:
-           FcCharSetPrepareSerialize(FcCharSetPtrU(v.u.ci));
-           break;
-       case FcTypeLangSet:
-           FcLangSetPrepareSerialize(FcLangSetPtrU(v.u.li));
-           break;
-       case FcTypeString:
-           FcObjectPrepareSerialize(v.u.si);
-       default:
-           break;
-       }
-       fcvaluelist_count++;
-    }
-    
-    return FcTrue;
-}
-
 FcPattern *
-FcPatternSerialize (FcPattern *old)
+FcPatternFilter (FcPattern *p, const FcObjectSet *os)
 {
-    FcPattern *p;
-    FcPatternElt *e, *nep;
-    FcValueList * nv;
-    FcValueListPtr v, nv_head, nvp;
-    int i, elts;
-
-    if (!fcpatterns)
-    {
-       p = malloc (sizeof (FcPattern) * fcpattern_count);
-       if (!p)
-           goto bail;
-
-       FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern) * fcpattern_count);
-       fcpatterns = p;
-       fcpattern_ptr = 0;
+    int                    i;
+    FcPattern      *ret;
+    FcPatternElt    *e;
+    FcValueListPtr  v;
 
-       e = malloc (sizeof (FcPatternElt) * fcpatternelt_count);
-       if (!e)
-           goto bail1;
+    if (!os)
+       return FcPatternDuplicate (p);
 
-       FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt) * fcpatternelt_count);
-       fcpatternelts = e;
-       fcpatternelt_ptr = 0;
-    }
+    ret = FcPatternCreate ();
+    if (!ret)
+       return NULL;
 
-    p = FcPatternCreate();
-    elts = fcpatternelt_ptr;
-    nep = &fcpatternelts[elts];
-    if (!nep)
-       return FcFalse;
-    fcpatternelt_ptr += old->num;
-    
-    for (e = FcPatternEltU(old->elts), i=0; i < old->num; i++, e++) 
+    for (i = 0; i < os->nobject; i++)
     {
-        v = e->values;
-        nvp = nv_head = FcValueListSerialize(FcValueListPtrU(v));
-        if (!FcValueListPtrU(nv_head))
-            goto bail2;
-       nv = FcValueListPtrU(nvp);
-       
-        for (;
-             FcValueListPtrU(v);
-             v = FcValueListPtrU(v)->next, 
-                nv = FcValueListPtrU(nv->next))
-        {
-           
-           if (FcValueListPtrU(FcValueListPtrU(v)->next))
+       FcObject object = FcObjectFromName (os->objects[i]);
+       e = FcPatternObjectFindElt (p, object);
+       if (e)
+       {
+           for (v = FcPatternEltValues(e); v; v = FcValueListNext(v))
            {
-                nvp = FcValueListSerialize
-                   (FcValueListPtrU(FcValueListPtrU(v)->next));
-                nv->next = nvp;
+               if (!FcPatternObjectAddWithBinding (ret, e->object,
+                                                   FcValueCanonicalize(&v->value),
+                                                   v->binding, FcTrue))
+                   goto bail0;
            }
-        }
-       
-       nep[i].values = nv_head;
-       nep[i].object = FcObjectSerialize
-           (FcObjectStaticName(FcObjectPtrU(e->object)));
-    }
-    
-    p->elts = FcPatternEltPtrCreateStatic(elts);
-    p->size = old->num;
-    p->ref = FC_REF_CONSTANT;
-    return p;
-    
- bail2:
-    free (fcpatternelts);
- bail1:
-    free (fcpatterns);
- bail:
-    return 0;
- }
-
-FcValueListPtr
-FcValueListSerialize(FcValueList *pi)
-{
-    FcValueListPtr new; 
-    FcValue * v;
-    FcValueList * vl;
-
-    if (!fcvaluelists)
-    {
-       vl = malloc (sizeof (FcValueList) * fcvaluelist_count);
-       if (!vl)
-           return FcValueListPtrCreateDynamic(0);
-
-       FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList) * fcvaluelist_count);
-       fcvaluelists = vl;
-       fcvaluelist_ptr = 0;
-    }
-
-    fcvaluelists[fcvaluelist_ptr] = *pi;
-    new.storage = FcStorageStatic;
-    new.u.stat = fcvaluelist_ptr++;
-    v = &fcvaluelists[new.u.stat].value;
-    switch (v->type)
-    {
-    case FcTypeString:
-       if (FcObjectPtrU(v->u.si))
-       {
-           FcObjectPtr si = 
-               FcObjectSerialize(FcObjectStaticName(FcObjectPtrU(v->u.si)));
-           if (!FcObjectPtrU(v->u.si))
-               return FcValueListPtrCreateDynamic(pi);
-           v->u.si = si;
-       }
-       break;
-    case FcTypeMatrix:
-       if (FcMatrixPtrU(v->u.mi))
-       {
-           FcMatrixPtr mi = FcMatrixSerialize(FcMatrixPtrU(v->u.mi));
-
-           if (!FcMatrixPtrU(mi))
-               return FcValueListPtrCreateDynamic(pi);
-           v->u.mi = mi;
-       }
-       break;
-    case FcTypeCharSet:
-       if (FcCharSetPtrU(v->u.ci))
-       {
-           FcCharSetPtr ci = FcCharSetSerialize(FcCharSetPtrU(v->u.ci));
-           if (!FcCharSetPtrU(v->u.ci))
-               return FcValueListPtrCreateDynamic(pi);
-           v->u.ci = ci;
-       }
-       break;
-    case FcTypeLangSet:
-       if (FcLangSetPtrU(v->u.li))
-       {
-           FcLangSetPtr li = FcLangSetSerialize(FcLangSetPtrU(v->u.li));
-           if (!FcLangSetPtrU(v->u.li))
-               return FcValueListPtrCreateDynamic(pi);
-           v->u.li = li;
        }
-       break;
-    default:
-       break;
-    }
-    return new;
-}
-
-FcValueList * 
-FcValueListPtrU (FcValueListPtr pi)
-{
-    switch (pi.storage)
-    {
-    case FcStorageStatic:
-       if (pi.u.stat == 0) return 0;
-        return &fcvaluelists[pi.u.stat];
-    case FcStorageDynamic:
-        return pi.u.dyn;
-    default:
-       return 0;
     }
-}
-
-FcValueListPtr
-FcValueListPtrCreateDynamic(FcValueList * p)
-{
-    FcValueListPtr r; 
+    return ret;
 
-    r.storage = FcStorageDynamic; 
-    r.u.dyn = p;
-    return r;
+bail0:
+    FcPatternDestroy (ret);
+    return NULL;
 }
 
-/* Indices allow us to convert dynamic strings into static
- * strings without having to reassign IDs.  We do reassign IDs
- * when serializing, which effectively performs mark-and-sweep 
- * garbage collection. */
-
-/* objectptr_count maps FcObjectPtr to:
-     + offsets in objectcontent_static_buf (if positive)
-     - entries in objectcontent_dynamic (if negative)
-*/
-static int objectptr_count = 1;
-static int objectptr_alloc = 0;
-static int * objectptr_indices = 0;
-
-/* invariant: objectcontent_static_buf must be sorted. */
-/* e.g. objectptr_static_buf = "name\0style\0weight\0" */
-static int objectcontent_static_bytes = 0;
-static char * objectcontent_static_buf;
-
-/* just a bunch of strings. */
-static int objectcontent_dynamic_count = 1;
-static int objectcontent_dynamic_alloc = 0;
-static const char ** objectcontent_dynamic = 0;
-static int * objectcontent_dynamic_refcount = 0;
-
 #define OBJECT_HASH_SIZE    31
-struct objectBucket {
+static struct objectBucket {
     struct objectBucket        *next;
     FcChar32           hash;
-};
-static struct objectBucket **buckets = 0;
+} *FcObjectBuckets[OBJECT_HASH_SIZE];
 
-FcObjectPtr
-FcObjectStaticName (const char *name)
+static FcBool
+FcHashOwnsName (const FcChar8 *name)
 {
-    FcChar32           hash = FcStringHash ((const FcChar8 *) name);
+    FcChar32           hash = FcStringHash (name);
     struct objectBucket        **p;
     struct objectBucket        *b;
-    const char *        nn;
-    int                        size;
-    FcObjectPtr                new;
 
-    if (!buckets)
-    {
-        buckets = malloc(sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
-        memset (buckets, 0, sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
-    }
-
-    for (p = &buckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
-    {
-       FcObjectPtr bp = *((FcObjectPtr *) (b + 1));
-       if (b->hash == hash && FcObjectPtrU(bp) && !strcmp (name, FcObjectPtrU(bp)))
-       {
-           if (objectptr_indices[bp] < 0)
-               objectcontent_dynamic_refcount[-objectptr_indices[bp]]++;
-           return bp;
-       }
-    }
+    for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
+       if (b->hash == hash && ((char *)name == (char *) (b + 1)))
+            return FcTrue;
+    return FcFalse;
+}
 
-    /* didn't find it, so add a new dynamic string */
-    if (objectcontent_dynamic_count >= objectcontent_dynamic_alloc)
-    {
-       int s = objectcontent_dynamic_alloc + 4;
-
-       const char ** d = realloc (objectcontent_dynamic, 
-                                  s*sizeof(char *));
-       if (!d)
-           return 0;
-       FcMemFree(FC_MEM_STATICSTR, 
-                 objectcontent_dynamic_alloc * sizeof(char *));
-       FcMemAlloc(FC_MEM_STATICSTR, s*sizeof(char *));
-       objectcontent_dynamic = d;
-       objectcontent_dynamic_alloc = s;
-
-       int * rc = realloc (objectcontent_dynamic_refcount, s*sizeof(int));
-       if (!rc)
-           return 0;
-       FcMemFree(FC_MEM_STATICSTR, 
-                 objectcontent_dynamic_alloc * sizeof(int));
-       FcMemAlloc(FC_MEM_STATICSTR, s * sizeof(int));
-       objectcontent_dynamic_refcount = rc;
-    }
-    if (objectptr_count >= objectptr_alloc)
-    {
-       int s = objectptr_alloc + 4;
-       int * d = realloc (objectptr_indices, s*sizeof(int));
-       if (!d)
-           return 0;
-       FcMemFree(FC_MEM_STATICSTR, objectptr_alloc * sizeof(int));
-       FcMemAlloc(FC_MEM_STATICSTR, s);
-       objectptr_indices = d;
-       objectptr_indices[0] = 0;
-       objectptr_alloc = s;
-    }
+const FcChar8 *
+FcStrStaticName (const FcChar8 *name)
+{
+    FcChar32           hash = FcStringHash (name);
+    struct objectBucket        **p;
+    struct objectBucket        *b;
+    int                        size;
 
-    size = sizeof (struct objectBucket) + sizeof (FcObjectPtr);
+    for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
+       if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
+           return (FcChar8 *) (b + 1);
+    size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
+    /*
+     * workaround valgrind warning because glibc takes advantage of how it knows memory is
+     * allocated to implement strlen by reading in groups of 4
+     */
+    size = (size + 3) & ~3;
     b = malloc (size);
-    if (!b)
-       return 0;
     FcMemAlloc (FC_MEM_STATICSTR, size);
+    if (!b)
+        return NULL;
     b->next = 0;
     b->hash = hash;
-    nn = malloc(strlen(name)+1);
-    if (!nn)
-        goto bail;
-    strcpy ((char *)nn, name);
-    objectptr_indices[objectptr_count] = -objectcontent_dynamic_count;
-    objectcontent_dynamic_refcount[objectcontent_dynamic_count] = 1;
-    objectcontent_dynamic[objectcontent_dynamic_count++] = nn;
-    new = objectptr_count++;
-    *((FcObjectPtr *)(b+1)) = new;
+    strcpy ((char *) (b + 1), (char *)name);
     *p = b;
-    return new;
-
- bail:
-    free(b);
-    return 0;
+    return (FcChar8 *) (b + 1);
 }
 
-void
-FcObjectPtrDestroy (FcObjectPtr p)
+static void
+FcStrStaticNameFini (void)
 {
-    if (objectptr_indices[p] < 0)
+    int i, size;
+    struct objectBucket *b, *next;
+    char *name;
+
+    for (i = 0; i < OBJECT_HASH_SIZE; i++)
     {
-       objectcontent_dynamic_refcount[-objectptr_indices[p]]--;
-       if (objectcontent_dynamic_refcount[-objectptr_indices[p]] == 0)
+       for (b = FcObjectBuckets[i]; b; b = next)
        {
-           /* this code doesn't seem to be reached terribly often. */
-           /* (note that objectcontent_dynamic overapproximates 
-            * the use count, because not every result from
-            * StaticName is stored. */
-           FcStrFree((char *)objectcontent_dynamic[-objectptr_indices[p]]);
-           objectcontent_dynamic[-objectptr_indices[p]] = 0;
+           next = b->next;
+           name = (char *) (b + 1);
+           size = sizeof (struct objectBucket) + strlen (name) + 1;
+           FcMemFree (FC_MEM_STATICSTR, size + sizeof (int));
+           free (b);
        }
+       FcObjectBuckets[i] = 0;
     }
 }
 
-const char *
-FcObjectPtrU (FcObjectPtr si)
+void
+FcPatternFini (void)
 {
-    if (objectptr_indices[si] > 0)
-       return &objectcontent_static_buf[objectptr_indices[si]];
-    else
-       return objectcontent_dynamic[-objectptr_indices[si]];
+    FcStrStaticNameFini ();
+    FcObjectFini ();
 }
 
-static FcBool objectptr_first_serialization = FcFalse;
-static int * object_old_id_to_new = 0;
-
-static void 
-FcObjectRebuildStaticNameHashtable (void)
+FcBool
+FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat)
 {
-    int i;
-    struct objectBucket        *b, *bn;
-
-    if (buckets)
-    {
-       for (i = 0; i < OBJECT_HASH_SIZE; i++)
-       {
-           b = buckets[i];
-           while (b)
-           {
-               bn = b->next;
-               free(b);
-               FcMemFree (FC_MEM_STATICSTR,
-                          sizeof (struct objectBucket)+sizeof (FcObjectPtr));
-               b = bn;
-           }
-       }
-       free (buckets);
-    }
-
-    buckets = malloc(sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
-    memset (buckets, 0, sizeof (struct objectBucket *)*OBJECT_HASH_SIZE);
+    int        i;
+    FcPatternElt    *elts = FcPatternElts(pat);
 
-    for (i = 1; i < objectptr_count; i++)
-    {
-       if (FcObjectPtrU(i))
-       {
-           const char * name = FcObjectPtrU(i);
-           FcChar32     hash = FcStringHash ((const FcChar8 *) name);
-           struct objectBucket **p;
-           int size;
-
-           for (p = &buckets[hash % OBJECT_HASH_SIZE]; (b = *p); 
-                p = &(b->next))
-               ;
-           size = sizeof (struct objectBucket) + sizeof (FcObjectPtr);
-           b = malloc (size);
-           if (!b)
-               return;
-           FcMemAlloc (FC_MEM_STATICSTR, size);
-           b->next = 0;
-           b->hash = hash;
-           *((FcObjectPtr *)(b+1)) = i;
-           *p = b;
-       }
-    }
+    if (!FcSerializeAlloc (serialize, pat, sizeof (FcPattern)))
+       return FcFalse;
+    if (!FcSerializeAlloc (serialize, elts, pat->num * sizeof (FcPatternElt)))
+       return FcFalse;
+    for (i = 0; i < pat->num; i++)
+       if (!FcValueListSerializeAlloc (serialize, FcPatternEltValues(elts+i)))
+           return FcFalse;
+    return FcTrue;
 }
 
-/* Hmm.  This will have a terrible effect on the memory size,
- * because the mmapped strings now get reallocated on the heap. 
- * Is it all worth it? (Of course, the Serialization codepath is
- * not problematic.) */
-static FcBool
-FcObjectPtrConvertToStatic(FcBool renumber)
+FcPattern *
+FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat)
 {
-    int active_count, i, j, longest_string = 0, 
-       new_static_bytes = 1;
-    char * fixed_length_buf, * new_static_buf, * p;
-    int * new_indices;
-
-    if (renumber)
-       objectptr_first_serialization = FcFalse;
+    FcPattern      *pat_serialized;
+    FcPatternElt    *elts = FcPatternElts (pat);
+    FcPatternElt    *elts_serialized;
+    FcValueList            *values_serialized;
+    int                    i;
 
-    /* collect statistics */
-    for (i = 1, active_count = 1; i < objectptr_count; i++)
-       if (!renumber || object_old_id_to_new[i] == -1)
-       {
-           int sl = strlen(FcObjectPtrU(i));
-           active_count++;
-           if (sl > longest_string)
-               longest_string = sl;
-           new_static_bytes += sl + 1;
-       } 
-
-    /* allocate storage */
-    fixed_length_buf = malloc 
-       ((longest_string+1) * active_count * sizeof(char));
-    if (!fixed_length_buf)
-       goto bail;
-    new_static_buf = malloc (new_static_bytes * sizeof(char));
-    if (!new_static_buf)
-       goto bail1;
-    new_indices = malloc (active_count * sizeof(int));
-    if (!new_indices)
-       goto bail2;
-    
-    FcMemAlloc (FC_MEM_STATICSTR, new_static_bytes);
-    FcMemFree (FC_MEM_STATICSTR, objectptr_count * sizeof (int));
-    FcMemAlloc (FC_MEM_STATICSTR, active_count * sizeof (int));
-    
-    /* copy strings to temporary buffers */
-    for (j = 0, i = 1; i < objectptr_count; i++)
-       if (!renumber || object_old_id_to_new[i] == -1)
-       {
-           strcpy (fixed_length_buf+(j*(longest_string+1)), FcObjectPtrU(i));
-           j++;
-       }
-    
-    /* sort the new statics */
-    qsort (fixed_length_buf, active_count-1, longest_string+1, 
-          (int (*)(const void *, const void *)) FcStrCmp);
-    
-    /* now we create the new static buffer in sorted order. */
-    p = new_static_buf+1;
-    for (i = 0; i < active_count-1; i++)
-    {
-       strcpy(p, fixed_length_buf + i * (longest_string+1));
-       p += strlen(p)+1;
-    }
+    pat_serialized = FcSerializePtr (serialize, pat);
+    if (!pat_serialized)
+       return NULL;
+    *pat_serialized = *pat;
+    pat_serialized->size = pat->num;
+    pat_serialized->ref = FC_REF_CONSTANT;
 
-    /* create translation table by iterating over sorted strings
-     * and getting their old values */
-    p = new_static_buf+1;
-    for (i = 0; i < active_count-1; i++)
-    {
-       int n = FcObjectStaticName(fixed_length_buf+i*(longest_string+1));
-       if (renumber)
-       {
-           object_old_id_to_new[n] = i;
-           new_indices[i] = p-new_static_buf;
-       }
-       else
-           new_indices[n] = p-new_static_buf;
-       p += strlen(p)+1;
-    }
+    elts_serialized = FcSerializePtr (serialize, elts);
+    if (!elts_serialized)
+       return NULL;
 
-    free (objectptr_indices);
-    objectptr_indices = new_indices;
-    objectptr_count = active_count;
-    objectptr_alloc = active_count;
+    pat_serialized->elts_offset = FcPtrToOffset (pat_serialized,
+                                                elts_serialized);
 
-    /* free old storage */
-    for (i = 1; i < objectcontent_dynamic_count; i++)
+    for (i = 0; i < pat->num; i++)
     {
-       if (objectcontent_dynamic[i])
-       {
-           FcMemFree (FC_MEM_STATICSTR, strlen(objectcontent_dynamic[i])+1);
-           free ((char *)objectcontent_dynamic[i]);
-       }       
+       values_serialized = FcValueListSerialize (serialize, FcPatternEltValues (elts+i));
+       if (!values_serialized)
+           return NULL;
+       elts_serialized[i].object = elts[i].object;
+       elts_serialized[i].values = FcPtrToEncodedOffset (&elts_serialized[i],
+                                                         values_serialized,
+                                                         FcValueList);
     }
-    free (objectcontent_dynamic);
-    free (objectcontent_dynamic_refcount);
-    FcMemFree (FC_MEM_STATICSTR, objectcontent_dynamic_count*sizeof (int));
-    objectcontent_dynamic = 0;
-    objectcontent_dynamic_refcount = 0;
-    objectcontent_dynamic_count = 1;
-    objectcontent_dynamic_alloc = 0;
-    free (objectcontent_static_buf);
-    FcMemFree (FC_MEM_STATICSTR, objectcontent_static_bytes);
-    objectcontent_static_buf = new_static_buf;
-    objectcontent_static_bytes = new_static_bytes;
-
-    /* fix up hash table */
-    FcObjectRebuildStaticNameHashtable();
-
-    free (fixed_length_buf);
-    return FcTrue;
-
- bail2: 
-    free (new_static_buf);
- bail1: 
-    free (fixed_length_buf);
- bail:
-    return FcFalse;
+    if (FcDebug() & FC_DBG_CACHEV) {
+       printf ("Raw pattern:\n");
+       FcPatternPrint (pat);
+       printf ("Serialized pattern:\n");
+       FcPatternPrint (pat_serialized);
+       printf ("\n");
+    }
+    return pat_serialized;
 }
 
-#define OBJECT_PTR_CONVERSION_TRIGGER 100000
-
-int
-FcObjectPtrCompare (const FcObjectPtr a, const FcObjectPtr b)
+FcBool
+FcValueListSerializeAlloc (FcSerialize *serialize, const FcValueList *vl)
 {
-    /* This is the dynamic count.  We could also use a static
-     * count, i.e. the number of slow strings being created.
-     * I think dyncount gives us a better estimate of inefficiency. -PL */
-    static int compare_count = OBJECT_PTR_CONVERSION_TRIGGER;
-
-    /* count on sortedness for fast objectptrs. */
-    if ((a == b) || (objectptr_indices[a] > 0 && objectptr_indices[b] > 0))
-       return objectptr_indices[a] - objectptr_indices[b];
-
-    compare_count--;
-    if (!compare_count)
+    while (vl)
     {
-       FcObjectPtrConvertToStatic(FcFalse);
-       compare_count = OBJECT_PTR_CONVERSION_TRIGGER;
+       if (!FcSerializeAlloc (serialize, vl, sizeof (FcValueList)))
+           return FcFalse;
+       switch (vl->value.type) {
+       case FcTypeString:
+           if (!FcStrSerializeAlloc (serialize, vl->value.u.s))
+               return FcFalse;
+           break;
+       case FcTypeCharSet:
+           if (!FcCharSetSerializeAlloc (serialize, vl->value.u.c))
+               return FcFalse;
+           break;
+       case FcTypeLangSet:
+           if (!FcLangSetSerializeAlloc (serialize, vl->value.u.l))
+               return FcFalse;
+           break;
+       default:
+           break;
+       }
+       vl = vl->next;
     }
-
-    return strcmp (FcObjectPtrU(a), FcObjectPtrU(b));
-}
-
-void
-FcObjectClearStatic(void)
-{
-    objectptr_count = 1;
-    objectptr_alloc = 0;
-    objectptr_indices = 0;
-
-    objectcontent_static_bytes = 0;
-    objectcontent_static_buf = 0;
-
-    objectcontent_dynamic_count = 1;
-    objectcontent_dynamic_alloc = 0;
-    objectcontent_dynamic = 0;
-    objectcontent_dynamic_refcount = 0;
-
-    object_old_id_to_new = 0;
+    return FcTrue;
 }
 
-static FcObjectPtr
-FcObjectSerialize (FcObjectPtr si)
+FcValueList *
+FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
 {
-    if (objectptr_first_serialization)
-       if (!FcObjectPtrConvertToStatic(FcTrue))
-           return 0;
-
-    return object_old_id_to_new[si];
-}
+    FcValueList        *vl_serialized;
+    FcChar8    *s_serialized;
+    FcCharSet  *c_serialized;
+    FcLangSet  *l_serialized;
+    FcValueList        *head_serialized = NULL;
+    FcValueList        *prev_serialized = NULL;
 
-/* In the pre-serialization phase, mark the used strings with
- * -1 in the mapping array. */
-/* The first call to the serialization phase assigns actual 
- * static indices to the strings (sweep). */
-FcBool
-FcObjectPrepareSerialize (FcObjectPtr si)
-{
-    if (object_old_id_to_new == 0)
+    while (vl)
     {
-       object_old_id_to_new = malloc(objectptr_count * sizeof(int));
-       if (!object_old_id_to_new)
-           goto bail;
-       memset (object_old_id_to_new, 0, 
-               objectptr_count * sizeof(int));
+       vl_serialized = FcSerializePtr (serialize, vl);
+       if (!vl_serialized)
+           return NULL;
+
+       if (prev_serialized)
+           prev_serialized->next = FcPtrToEncodedOffset (prev_serialized,
+                                                         vl_serialized,
+                                                         FcValueList);
+       else
+           head_serialized = vl_serialized;
+       
+       vl_serialized->next = NULL;
+       vl_serialized->value.type = vl->value.type;
+       switch (vl->value.type) {
+       case FcTypeInteger:
+           vl_serialized->value.u.i = vl->value.u.i;
+           break;
+       case FcTypeDouble:
+           vl_serialized->value.u.d = vl->value.u.d;
+           break;
+       case FcTypeString:
+           s_serialized = FcStrSerialize (serialize, vl->value.u.s);
+           if (!s_serialized)
+               return NULL;
+           vl_serialized->value.u.s = FcPtrToEncodedOffset (&vl_serialized->value,
+                                                            s_serialized,
+                                                            FcChar8);
+           break;
+       case FcTypeBool:
+           vl_serialized->value.u.b = vl->value.u.b;
+           break;
+       case FcTypeMatrix:
+           /* can't happen */
+           break;
+       case FcTypeCharSet:
+           c_serialized = FcCharSetSerialize (serialize, vl->value.u.c);
+           if (!c_serialized)
+               return NULL;
+           vl_serialized->value.u.c = FcPtrToEncodedOffset (&vl_serialized->value,
+                                                            c_serialized,
+                                                            FcCharSet);
+           break;
+       case FcTypeFTFace:
+           /* can't happen */
+           break;
+       case FcTypeLangSet:
+           l_serialized = FcLangSetSerialize (serialize, vl->value.u.l);
+           if (!l_serialized)
+               return NULL;
+           vl_serialized->value.u.l = FcPtrToEncodedOffset (&vl_serialized->value,
+                                                            l_serialized,
+                                                            FcLangSet);
+           break;
+       default:
+           break;
+       }
+       prev_serialized = vl_serialized;
+       vl = vl->next;
     }
-
-    object_old_id_to_new[si] = -1;
-    objectptr_first_serialization = FcTrue;
-
-    return FcTrue;
-
- bail:
-    return FcFalse;
+    return head_serialized;
 }
+#define __fcpat__
+#include "fcaliastail.h"
+#include "fcftaliastail.h"
+#undef __fcpat__