]> git.wh0rd.org Git - fontconfig.git/commitdiff
Make FcCompareString and FcCompareFamily less expensive. Only add a value
authorPatrick Lam <plam@MIT.EDU>
Thu, 24 Nov 2005 20:20:26 +0000 (20:20 +0000)
committerPatrick Lam <plam@MIT.EDU>
Thu, 24 Nov 2005 20:20:26 +0000 (20:20 +0000)
    for FC_FAMILY if the proposed value is a string.
reviewed by: plam

ChangeLog
src/fcmatch.c
src/fcpat.c

index ac81063467c3879a0e040e8b5d55e170be51146d..bea96dde9392347746cb92d52f221412186a3a7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,13 @@
-2005-11-24  Dirk Mueller <dmueller@suse.com>
+2005-11-24  Dirk Mueller  <dmueller@suse.com>
+       reviewed by: plam
+
+       * src/fcmatch.c (FcCompareNumber, FcCompareString, FcCompareFamily):
+       * src/fcpat.c (FcPatternAddWithBinding):
+
+       Make FcCompareString and FcCompareFamily less expensive.
+       Only add a value for FC_FAMILY if the proposed value is a string.
+
+2005-11-24  Dirk Mueller  <dmueller@suse.com>
        reviewed by: plam
        
        * src/fcdbg.c (FcDebug, FcDebugInit, FcPatternPrint):
index 49d41a4ad63513569dd546bede96d89db81d5704..8b0bd014f4d8a10de9abbd1f163ea4b45bcf2557 100644 (file)
@@ -55,25 +55,35 @@ FcCompareNumber (const char *object, FcValue *value1, FcValue *value2)
     v = v2 - v1;
     if (v < 0)
        v = -v;
-    return (double) v;
+    return v;
 }
 
 static double
 FcCompareString (const char *object, FcValue *v1, FcValue *v2)
 {
-    FcValue value1 = FcValueCanonicalize(v1), value2 = FcValueCanonicalize(v2);
-    if (value2.type != FcTypeString || value1.type != FcTypeString)
+    FcValue value1, value2;
+    if ((v2->type & ~FC_STORAGE_STATIC) != FcTypeString || 
+        (v1->type & ~FC_STORAGE_STATIC) != FcTypeString)
        return -1.0;
+    value1 = FcValueCanonicalize(v1); value2 = FcValueCanonicalize(v2);
     return (double) FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0;
 }
 
 static double
 FcCompareFamily (const char *object, FcValue *v1, FcValue *v2)
 {
-    FcValue value1 = FcValueCanonicalize(v1), value2 = FcValueCanonicalize(v2);
-    if (value2.type != FcTypeString || value1.type != FcTypeString)
-       return -1.0;
-    return (double) FcStrCmpIgnoreBlanksAndCase (value1.u.s, value2.u.s) != 0;
+    /* rely on the guarantee in FcPatternAddWithBinding that
+     * families are always FcTypeString. */
+
+    /* assert ((v2->type & ~FC_STORAGE_STATIC) == FcTypeString && 
+       (v1->type & ~FC_STORAGE_STATIC) == FcTypeString); */
+    const FcChar8* v1_string = fc_value_string(v1);
+    const FcChar8* v2_string = fc_value_string(v2);
+
+    if (FcToLower(*v1_string) != FcToLower(*v2_string))
+       return 1.0;
+
+    return (double) FcStrCmpIgnoreBlanksAndCase (v1_string, v2_string) != 0;
 }
 
 static double
index a82fb6fb03a7223ee08286cab1f66f2de9714354..c37936f397133993fbaac14eb38382461551b9cb 100644 (file)
@@ -872,6 +872,13 @@ FcPatternAddWithBinding  (FcPattern            *p,
     if (value.type == FcTypeVoid)
        goto bail1;
 
+    /* quick and dirty hack to enable FcCompareFamily speedup:
+     * only allow strings to be added under the FC_FAMILY key.
+     * a better hack would use FcBaseObjectTypes to check all objects. */
+    if (FcObjectToPtr(object) == FcObjectToPtr(FC_FAMILY) &&
+        value.type != FcTypeString)
+        goto bail1;
+
     FcValueListPtrU(new)->value = value;
     FcValueListPtrU(new)->binding = binding;
     FcValueListPtrU(new)->next = FcValueListPtrCreateDynamic(0);