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.
This commit is contained in:
parent
1b0cb23adc
commit
922168afe8
|
@ -408,6 +408,7 @@ FcCompareValueList (FcObject object,
|
||||||
FcValueListPtr v1, v2;
|
FcValueListPtr v1, v2;
|
||||||
double v, best, bestStrong, bestWeak;
|
double v, best, bestStrong, bestWeak;
|
||||||
int j, k, pos = 0;
|
int j, k, pos = 0;
|
||||||
|
int weak, strong;
|
||||||
|
|
||||||
if (!match)
|
if (!match)
|
||||||
{
|
{
|
||||||
|
@ -418,11 +419,13 @@ FcCompareValueList (FcObject object,
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
weak = match->weak;
|
||||||
|
strong = match->strong;
|
||||||
|
|
||||||
best = 1e99;
|
best = 1e99;
|
||||||
bestStrong = 1e99;
|
bestStrong = 1e99;
|
||||||
bestWeak = 1e99;
|
bestWeak = 1e99;
|
||||||
j = 0;
|
for (v1 = v1orig, j = 0; v1; v1 = FcValueListNext(v1), j++)
|
||||||
for (v1 = v1orig; v1; v1 = FcValueListNext(v1))
|
|
||||||
{
|
{
|
||||||
for (v2 = v2orig, k = 0; v2; v2 = FcValueListNext(v2), k++)
|
for (v2 = v2orig, k = 0; v2; v2 = FcValueListNext(v2), k++)
|
||||||
{
|
{
|
||||||
|
@ -441,7 +444,13 @@ FcCompareValueList (FcObject object,
|
||||||
best = v;
|
best = v;
|
||||||
pos = k;
|
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)
|
if (v < bestStrong)
|
||||||
bestStrong = v;
|
bestStrong = v;
|
||||||
|
@ -452,8 +461,8 @@ FcCompareValueList (FcObject object,
|
||||||
bestWeak = v;
|
bestWeak = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
if (FcDebug () & FC_DBG_MATCHV)
|
if (FcDebug () & FC_DBG_MATCHV)
|
||||||
{
|
{
|
||||||
printf (" %s: %g ", FcObjectName (object), best);
|
printf (" %s: %g ", FcObjectName (object), best);
|
||||||
|
@ -464,8 +473,6 @@ FcCompareValueList (FcObject object,
|
||||||
}
|
}
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
int weak = match->weak;
|
|
||||||
int strong = match->strong;
|
|
||||||
if (weak == strong)
|
if (weak == strong)
|
||||||
value[strong] += best;
|
value[strong] += best;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue