Improve the performance on searching blanks
After the change of d6a5cc665a
we have a lot of code points in FcBlanks. doing the linear search
on the array isn't comfortable anymore.
So re-implementing FcBlanksIsMember() to use the binary search.
Figuring out how much improved after this change depends on
how many fonts proceed with fc-cache say though, it's about 20 times
faster here on testing. which sounds good enough for
improvement.
This commit is contained in:
parent
d997d7c770
commit
96a3f6879c
|
@ -82,11 +82,26 @@ FcBlanksAdd (FcBlanks *b, FcChar32 ucs4)
|
||||||
FcBool
|
FcBool
|
||||||
FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4)
|
FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4)
|
||||||
{
|
{
|
||||||
int i;
|
int lower = 0, higher = b->nblank, middle;
|
||||||
|
|
||||||
for (i = 0; i < b->nblank; i++)
|
if (b->nblank == 0 ||
|
||||||
if (b->blanks[i] == ucs4)
|
b->blanks[0] > ucs4 ||
|
||||||
|
b->blanks[b->nblank - 1] < ucs4)
|
||||||
|
return FcFalse;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
middle = (lower + higher) / 2;
|
||||||
|
if (b->blanks[middle] == ucs4)
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
if (middle == lower ||
|
||||||
|
middle == higher)
|
||||||
|
break;
|
||||||
|
if (b->blanks[middle] < ucs4)
|
||||||
|
lower = middle + 1;
|
||||||
|
else
|
||||||
|
higher = middle - 1;
|
||||||
|
}
|
||||||
|
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
}
|
}
|
||||||
#define __fcblanks__
|
#define __fcblanks__
|
||||||
|
|
Loading…
Reference in New Issue