@@ -143,22 +143,25 @@ class NMTPreInitAllocationTable {
143
143
// VMs with insanely long command lines maybe ~700-1000. Which gives us an expected
144
144
// load factor of ~.1. Hash collisions should be very rare.
145
145
// ~8000 entries cost us ~64K for this table (64-bit), which is acceptable.
146
- static const int table_size = 7919 ;
146
+ // We chose 8191, as this is a Mersenne prime (2^x - 1), which for a random
147
+ // polynomial modulo p = (2^x - 1) is uniformily distributed in [p], so each
148
+ // bit has the same distribution.
149
+ static const int table_size = 8191 ; // i.e. 8191==(2^13 - 1);
147
150
148
151
NMTPreInitAllocation* _entries[table_size];
149
152
150
153
typedef int index_t ;
151
154
const index_t invalid_index = -1 ;
152
155
153
- static unsigned calculate_hash (const void * p) {
154
- uintptr_t tmp = p2i (p);
155
- unsigned hash = (unsigned )tmp
156
- LP64_ONLY ( ^ (unsigned )(tmp >> 32 ));
157
- return hash;
156
+ static uint64_t calculate_hash (const void * p) {
157
+ // Keep hash function simple, the modulo
158
+ // operation in index function will do the "heavy lifting".
159
+ return (uint64_t )(p);
158
160
}
159
161
160
162
static index_t index_for_key (const void * p) {
161
- const unsigned hash = calculate_hash (p);
163
+ const uint64_t hash = calculate_hash (p);
164
+ // "table_size" is a Mersenne prime, so "modulo" is all we need here.
162
165
return hash % table_size;
163
166
}
164
167
0 commit comments