From 4f76f956bb3a95b307322cdad4f8d3b97851678e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 1 Jun 2018 17:28:47 -0700 Subject: [PATCH] [map] Move prime_for to hb-static --- src/hb-map-private.hh | 53 +------------------------------------------ src/hb-private.hh | 2 ++ src/hb-static.cc | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/hb-map-private.hh b/src/hb-map-private.hh index cad6f0e2..7f6b02c5 100644 --- a/src/hb-map-private.hh +++ b/src/hb-map-private.hh @@ -39,49 +39,6 @@ inline uint32_t Hash (const T &v) } -/* Following comment and table copied from glib. */ -/* Each table size has an associated prime modulo (the first prime - * lower than the table size) used to find the initial bucket. Probing - * then works modulo 2^n. The prime modulo is necessary to get a - * good distribution with poor hash functions. - */ -static const unsigned int prime_mod [] = -{ - 1, /* For 1 << 0 */ - 2, - 3, - 7, - 13, - 31, - 61, - 127, - 251, - 509, - 1021, - 2039, - 4093, - 8191, - 16381, - 32749, - 65521, /* For 1 << 16 */ - 131071, - 262139, - 524287, - 1048573, - 2097143, - 4194301, - 8388593, - 16777213, - 33554393, - 67108859, - 134217689, - 268435399, - 536870909, - 1073741789, - 2147483647 /* For 1 << 31 */ -}; - - /* * hb_map_t */ @@ -148,7 +105,7 @@ struct hb_map_t /* Switch to new, empty, array. */ population = occupancy = 0; mask = new_size - 1; - prime = prime_for (power); + prime = _hb_prime_for (power); items = new_items; /* Insert back old items. */ @@ -226,14 +183,6 @@ struct hb_map_t protected: - static inline unsigned int prime_for (unsigned int shift) - { - if (unlikely (shift >= ARRAY_LENGTH (prime_mod))) - return prime_mod[ARRAY_LENGTH (prime_mod) - 1]; - - return prime_mod[shift]; - } - inline unsigned int bucket_for (hb_codepoint_t key) const { unsigned int i = Hash (key) % prime; diff --git a/src/hb-private.hh b/src/hb-private.hh index 74045d7e..e96af550 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1231,5 +1231,7 @@ round (double x) #endif +HB_INTERNAL unsigned int _hb_prime_for (unsigned int shift); + #endif /* HB_PRIVATE_HH */ diff --git a/src/hb-static.cc b/src/hb-static.cc index e26e5c80..aa0871d5 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -30,3 +30,54 @@ void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; /*thread_local*/ void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif + + +/* Following comment and table copied from glib. */ +/* Each table size has an associated prime modulo (the first prime + * lower than the table size) used to find the initial bucket. Probing + * then works modulo 2^n. The prime modulo is necessary to get a + * good distribution with poor hash functions. + */ +static const unsigned int prime_mod [] = +{ + 1, /* For 1 << 0 */ + 2, + 3, + 7, + 13, + 31, + 61, + 127, + 251, + 509, + 1021, + 2039, + 4093, + 8191, + 16381, + 32749, + 65521, /* For 1 << 16 */ + 131071, + 262139, + 524287, + 1048573, + 2097143, + 4194301, + 8388593, + 16777213, + 33554393, + 67108859, + 134217689, + 268435399, + 536870909, + 1073741789, + 2147483647 /* For 1 << 31 */ +}; + +unsigned int _hb_prime_for (unsigned int shift) +{ + if (unlikely (shift >= ARRAY_LENGTH (prime_mod))) + return prime_mod[ARRAY_LENGTH (prime_mod) - 1]; + + return prime_mod[shift]; +} -- GitLab