]> git.wh0rd.org - fontconfig.git/commitdiff
Add FcPatternHash, clean up a few valgrind issues
authorKeith Packard <keithp@keithp.com>
Sat, 8 Jun 2002 17:32:05 +0000 (17:32 +0000)
committerKeith Packard <keithp@keithp.com>
Sat, 8 Jun 2002 17:32:05 +0000 (17:32 +0000)
fontconfig/fontconfig.h
src/fccfg.c
src/fcmatch.c
src/fcpat.c
src/fcxml.c

index 3d00ec0554ad1c77739e6bdcf94b365d662d6d3a..d7e102390d97872ac80924ad31a436e0fc90b318 100644 (file)
@@ -603,6 +603,9 @@ FcPatternEqual (const FcPattern *pa, const FcPattern *pb);
 FcBool
 FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os);
 
+FcChar32
+FcPatternHash (const FcPattern *p);
+
 FcBool
 FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append);
     
index 0cee6de3d2dbcaac5c597391bdde0a5012a1db68..baa1cbcc364c2c7924c9a4be37c45481adcc0b3c 100644 (file)
@@ -901,8 +901,8 @@ FcConfigMatchValueList (FcPattern   *p,
                }
            }
        }
+       FcValueDestroy (value);
     }
-    FcValueDestroy (value);
     return ret;
 }
 
index c616c631f83b27b9f65b73230fb0c840b7e8278a..a95e5f6c37d422d975ce6fbbb9d389b5ee271039 100644 (file)
@@ -250,7 +250,8 @@ FcCompareValueList (const char  *object,
        FcValueListPrint (v2orig);
        printf ("\n");
     }
-    value[i] += best;
+    if (value)
+       value[i] += best;
     return FcTrue;
 }
 
@@ -317,7 +318,6 @@ FcFontRenderPrepare (FcConfig           *config,
     int                    i;
     FcPatternElt    *fe, *pe;
     FcValue        v;
-    double         score[NUM_MATCHER];
     FcResult       result;
     
     new = FcPatternCreate ();
@@ -330,7 +330,7 @@ FcFontRenderPrepare (FcConfig           *config,
        if (pe)
        {
            if (!FcCompareValueList (pe->object, pe->values, 
-                                    fe->values, &v, score, &result))
+                                    fe->values, &v, 0, &result))
            {
                FcPatternDestroy (new);
                return 0;
@@ -598,7 +598,10 @@ FcFontSetSort (FcConfig        *config,
     if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim))
        goto bail2;
 
-    *csp = cs;
+    if (csp)
+       *csp = cs;
+    else
+       FcCharSetDestroy (cs);
 
     free (nodes);
 
index 68ded728c068eb406fd7b995cebce3dd04773fc5..e212fa05d8c7c5d795f464e42f4db8d7279a564a 100644 (file)
@@ -148,6 +148,56 @@ FcValueEqual (FcValue va, FcValue vb)
     return FcFalse;
 }
 
+static FcChar32
+FcDoubleHash (double d)
+{
+    if (d < 0)
+       d = -d;
+    if (d > 0xffffffff)
+       d = 0xffffffff;
+    return (FcChar32) d;
+}
+
+static FcChar32
+FcStringHash (const FcChar8 *s)
+{
+    FcChar8    c;
+    FcChar32   h = 0;
+    
+    if (s)
+       while ((c = *s++))
+           h = ((h << 1) | (h >> 31)) ^ c;
+    return h;
+}
+
+static FcChar32
+FcValueHash (FcValue v)
+{
+    switch (v.type) {
+    case FcTypeVoid:
+       return 0;
+    case FcTypeInteger:
+       return (FcChar32) v.u.i;
+    case FcTypeDouble:
+       return FcDoubleHash (v.u.d);
+    case FcTypeString:
+       return FcStringHash (v.u.s);
+    case FcTypeBool:
+       return (FcChar32) v.u.b;
+    case FcTypeMatrix:
+       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) v.u.c->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 FcFalse;
+}
+
 static FcBool
 FcValueListEqual (FcValueList *la, FcValueList *lb)
 {
@@ -163,6 +213,19 @@ FcValueListEqual (FcValueList *la, FcValueList *lb)
     return FcTrue;
 }
 
+static FcChar32
+FcValueListHash (FcValueList *l)
+{
+    FcChar32   hash = 0;
+    
+    while (l)
+    {
+       hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (l->value);
+       l = l->next;
+    }
+    return hash;
+}
+
 void
 FcPatternDestroy (FcPattern *p)
 {
@@ -283,6 +346,21 @@ FcPatternEqual (const FcPattern *pa, const FcPattern *pb)
     return FcTrue;
 }
 
+FcChar32
+FcPatternHash (const FcPattern *p)
+{
+    int                i;
+    FcChar32   h = 0;
+
+    for (i = 0; i < p->num; i++)
+    {
+       h = (((h << 1) | (h >> 31)) ^ 
+            FcStringHash ((const FcChar8 *) p->elts[i].object) ^
+            FcValueListHash (p->elts[i].values));
+    }
+    return h;
+}
+
 FcBool
 FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os)
 {
index 09aa79ebaaed79f86984720bafdbe3a2858e5fa3..ef116d05aa08d4c749734defee29094f75c3a525 100644 (file)
 #include <stdarg.h>
 #include "fcint.h"
 
+#ifndef HAVE_EXPAT
+#define HAVE_EXPAT 1
+#endif
+
+#ifndef HAVE_XML2
+#define HAVE_XML2 0
+#endif
+
 #if HAVE_EXPAT
+#ifndef HAVE_XMLPARSE_H
+#define HAVE_XMLPARSE_H 0
+#endif
 #if HAVE_XMLPARSE_H
 #include <xmlparse.h>
 #else
@@ -1135,7 +1146,7 @@ FcParseAlias (FcConfigParse *parse)
     if (edit)
     {
        test = FcTestCreate (FcQualAny,
-                            FcStrCopy ((FcChar8 *) "family"),
+                            FC_FAMILY,
                             FcOpEqual,
                             family);
        if (test)