FcCharSetFreezeOrig(), FcCharSetFindFrozen(): use all buckets of freezer->orig_hash_table

As written at:

  https://lists.freedesktop.org/archives/fontconfig/2017-June/005929.html

I think FcCharSetFreezeOrig() and FcCharSetFindFrozen() should use the %
operator instead of & when computing the bucket index for
freezer->orig_hash_table, otherwise at most 8 buckets among the 67
available (FC_CHAR_SET_HASH_SIZE) are used.

Another way would be to change FC_CHAR_SET_HASH_SIZE to be of the form
2**n -1 (i.e., a power of two minus one). In such a case, the & and %
operators would be equivalent.
This commit is contained in:
Florent Rougon 2017-06-08 16:13:29 +02:00 committed by Akira TAGOH
parent 7940ada7a8
commit 60e1fe550a
1 changed files with 2 additions and 2 deletions

View File

@ -1120,7 +1120,7 @@ FcCharSetHash (FcCharSet *fcs)
static FcBool static FcBool
FcCharSetFreezeOrig (FcCharSetFreezer *freezer, const FcCharSet *orig, const FcCharSet *frozen) FcCharSetFreezeOrig (FcCharSetFreezer *freezer, const FcCharSet *orig, const FcCharSet *frozen)
{ {
FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE]; FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) % FC_CHAR_SET_HASH_SIZE];
FcCharSetOrigEnt *ent; FcCharSetOrigEnt *ent;
ent = malloc (sizeof (FcCharSetOrigEnt)); ent = malloc (sizeof (FcCharSetOrigEnt));
@ -1204,7 +1204,7 @@ FcCharSetFreezeBase (FcCharSetFreezer *freezer, FcCharSet *fcs)
static const FcCharSet * static const FcCharSet *
FcCharSetFindFrozen (FcCharSetFreezer *freezer, const FcCharSet *orig) FcCharSetFindFrozen (FcCharSetFreezer *freezer, const FcCharSet *orig)
{ {
FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE]; FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) % FC_CHAR_SET_HASH_SIZE];
FcCharSetOrigEnt *ent; FcCharSetOrigEnt *ent;
for (ent = *bucket; ent; ent = ent->next) for (ent = *bucket; ent; ent = ent->next)