Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Add FcPreprocessFamily speeding up FcCompareFamliy.
Browse files Browse the repository at this point in the history
FcPreprocessString calculates hash of the family string to fast reject not matching families.

TODO: Add benchmark numbers.
  • Loading branch information
michalsrb authored and Artoria2e5 committed Feb 16, 2018
1 parent 56617b2 commit 9784fbf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/fcmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,37 @@ FcCompareString (const FcValue *v1,
return (double) FcStrCmpIgnoreCase (FcValueString(v1), FcValueString(v2)) != 0;
}

static FcPrepValue
FcPreprocessFamily (FcValue *v)
{
FcPrepValue prep;
prep.type = FcPrepStrHashIgnoreBlanksAndCase;
prep.str_hash = FcStrHashIgnoreBlanksAndCase(FcValueString(v));
return prep;
}

static double
FcCompareFamily (const FcValue *v1,
const FcPrepValue *p1,
const FcValue *v2,
const FcPrepValue *p2,
FcValue *bestValue)
{
*bestValue = FcValueCanonicalize (v2);

if (p1->type == FcPrepStrHashIgnoreBlanksAndCase &&
p2->type == FcPrepStrHashIgnoreBlanksAndCase)
{
// If hashes are not matching, return fast
if (p1->str_hash != p2->str_hash)
return 1.0;
}

/* rely on the guarantee in FcPatternObjectAddWithBinding that
* families are always FcTypeString. */
const FcChar8* v1_string = FcValueString(v1);
const FcChar8* v2_string = FcValueString(v2);

*bestValue = FcValueCanonicalize (v2);

if (FcToLower(*v1_string) != FcToLower(*v2_string) &&
*v1_string != ' ' && *v2_string != ' ')
return 1.0;
Expand Down
2 changes: 1 addition & 1 deletion src/fcobjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* DON'T REORDER! The order is part of the cache signature. */
FC_OBJECT (FAMILY, FcTypeString, FcCompareFamily, NULL)
FC_OBJECT (FAMILY, FcTypeString, FcCompareFamily, FcPreprocessFamily)
FC_OBJECT (FAMILYLANG, FcTypeString, NULL, NULL)
FC_OBJECT (STYLE, FcTypeString, FcCompareString, FcPreprocessString)
FC_OBJECT (STYLELANG, FcTypeString, NULL, NULL)
Expand Down

0 comments on commit 9784fbf

Please sign in to comment.