Make FcCompareString and FcCompareFamily less expensive. Only add a value

for FC_FAMILY if the proposed value is a string.
reviewed by: plam
This commit is contained in:
Patrick Lam 2005-11-24 20:20:26 +00:00
parent b97a34b592
commit 4f8b266fd9
3 changed files with 34 additions and 8 deletions

View File

@ -1,3 +1,12 @@
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> 2005-11-24 Dirk Mueller <dmueller@suse.com>
reviewed by: plam reviewed by: plam

View File

@ -55,25 +55,35 @@ FcCompareNumber (const char *object, FcValue *value1, FcValue *value2)
v = v2 - v1; v = v2 - v1;
if (v < 0) if (v < 0)
v = -v; v = -v;
return (double) v; return v;
} }
static double static double
FcCompareString (const char *object, FcValue *v1, FcValue *v2) FcCompareString (const char *object, FcValue *v1, FcValue *v2)
{ {
FcValue value1 = FcValueCanonicalize(v1), value2 = FcValueCanonicalize(v2); FcValue value1, value2;
if (value2.type != FcTypeString || value1.type != FcTypeString) if ((v2->type & ~FC_STORAGE_STATIC) != FcTypeString ||
(v1->type & ~FC_STORAGE_STATIC) != FcTypeString)
return -1.0; return -1.0;
value1 = FcValueCanonicalize(v1); value2 = FcValueCanonicalize(v2);
return (double) FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0; return (double) FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0;
} }
static double static double
FcCompareFamily (const char *object, FcValue *v1, FcValue *v2) FcCompareFamily (const char *object, FcValue *v1, FcValue *v2)
{ {
FcValue value1 = FcValueCanonicalize(v1), value2 = FcValueCanonicalize(v2); /* rely on the guarantee in FcPatternAddWithBinding that
if (value2.type != FcTypeString || value1.type != FcTypeString) * families are always FcTypeString. */
return -1.0;
return (double) FcStrCmpIgnoreBlanksAndCase (value1.u.s, value2.u.s) != 0; /* 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 static double

View File

@ -872,6 +872,13 @@ FcPatternAddWithBinding (FcPattern *p,
if (value.type == FcTypeVoid) if (value.type == FcTypeVoid)
goto bail1; 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)->value = value;
FcValueListPtrU(new)->binding = binding; FcValueListPtrU(new)->binding = binding;
FcValueListPtrU(new)->next = FcValueListPtrCreateDynamic(0); FcValueListPtrU(new)->next = FcValueListPtrCreateDynamic(0);