diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-08-21 08:19:13 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-08-25 12:15:18 -0400 |
commit | 922168afe8bf48e872dc0a808fadefaa798a42ce (patch) | |
tree | 4f20bc33a3a9ea482b69f8a5b6f8ed63b6c7218a | |
parent | 1b0cb23adcdf0c2b136b41d805b157f0c6d75ad4 (diff) | |
download | fontconfig-922168afe8bf48e872dc0a808fadefaa798a42ce.tar.gz |
Speed up fonthashint matching
When we don't need to differentiate between weak and strong,
we can exit the loop in FcCompareValueList once we found a
best match.
This change helps reducing the amount of list walking we do
for fonthashint, where careless config files end up creating
lists with ~100 booleans :( We don't want to walk all those
to the end, over and over again.
We are already special-casing family, and the only other case
where weak != strong, PostScript names, doesn't have long lists
of values, so the limitation to weak == strong doesn't matter
much in practice.
-rw-r--r-- | src/fcmatch.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/fcmatch.c b/src/fcmatch.c index 969b855..289204e 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -408,6 +408,7 @@ FcCompareValueList (FcObject object, FcValueListPtr v1, v2; double v, best, bestStrong, bestWeak; int j, k, pos = 0; + int weak, strong; if (!match) { @@ -418,11 +419,13 @@ FcCompareValueList (FcObject object, return FcTrue; } + weak = match->weak; + strong = match->strong; + best = 1e99; bestStrong = 1e99; bestWeak = 1e99; - j = 0; - for (v1 = v1orig; v1; v1 = FcValueListNext(v1)) + for (v1 = v1orig, j = 0; v1; v1 = FcValueListNext(v1), j++) { for (v2 = v2orig, k = 0; v2; v2 = FcValueListNext(v2), k++) { @@ -441,7 +444,13 @@ FcCompareValueList (FcObject object, best = v; pos = k; } - if (v1->binding == FcValueBindingStrong) + if (weak == strong) + { + /* found the best possible match */ + if (best < 1000) + goto done; + } + else if (v1->binding == FcValueBindingStrong) { if (v < bestStrong) bestStrong = v; @@ -452,8 +461,8 @@ FcCompareValueList (FcObject object, bestWeak = v; } } - j++; } +done: if (FcDebug () & FC_DBG_MATCHV) { printf (" %s: %g ", FcObjectName (object), best); @@ -464,8 +473,6 @@ FcCompareValueList (FcObject object, } if (value) { - int weak = match->weak; - int strong = match->strong; if (weak == strong) value[strong] += best; else |