aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-01-15 09:25:02 +0100
committerMattias EngdegÄrd2024-02-06 14:50:40 +0100
commite66870400d45e3d08265df9f6acd4631a5712139 (patch)
treeca09e703762f4ebbdba620293e5265ea42b3016a /src/alloc.c
parentf6225d125c07bbde8c828b40eb6e81333e051c2a (diff)
downloademacs-e66870400d45e3d08265df9f6acd4631a5712139.tar.gz
emacs-e66870400d45e3d08265df9f6acd4631a5712139.zip
Change hash range reduction from remainder to multiplication
This makes both lookups and rehashing cheaper. The index vector size is now always a power of 2. The first table size is reduced to 6 (from 8), because index vectors would become excessively big otherwise. * src/lisp.h (struct Lisp_Hash_Table): Replace index_size with index_bits. All references adapted. (hash_table_index_size): New accessor; use it where applicable. * src/fns.c (hash_index_size): Replace with... (compute_hash_index_bits): ...this new function, returning the log2 of the index size. All callers adapted. (hash_index_index): Knuth multiplicative hashing instead of remainder. (maybe_resize_hash_table): Reduce first table size from 8 to 6.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 15bb65cf74f..6abe9e28650 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3443,7 +3443,7 @@ cleanup_vector (struct Lisp_Vector *vector)
3443 struct Lisp_Hash_Table *h = PSEUDOVEC_STRUCT (vector, Lisp_Hash_Table); 3443 struct Lisp_Hash_Table *h = PSEUDOVEC_STRUCT (vector, Lisp_Hash_Table);
3444 if (h->table_size > 0) 3444 if (h->table_size > 0)
3445 { 3445 {
3446 eassert (h->index_size > 1); 3446 eassert (h->index_bits > 0);
3447 xfree (h->index); 3447 xfree (h->index);
3448 xfree (h->key_and_value); 3448 xfree (h->key_and_value);
3449 xfree (h->next); 3449 xfree (h->next);
@@ -3451,7 +3451,7 @@ cleanup_vector (struct Lisp_Vector *vector)
3451 ptrdiff_t bytes = (h->table_size * (2 * sizeof *h->key_and_value 3451 ptrdiff_t bytes = (h->table_size * (2 * sizeof *h->key_and_value
3452 + sizeof *h->hash 3452 + sizeof *h->hash
3453 + sizeof *h->next) 3453 + sizeof *h->next)
3454 + h->index_size * sizeof *h->index); 3454 + hash_table_index_size (h) * sizeof *h->index);
3455 hash_table_allocated_bytes -= bytes; 3455 hash_table_allocated_bytes -= bytes;
3456 } 3456 }
3457 } 3457 }
@@ -5959,7 +5959,8 @@ purecopy_hash_table (struct Lisp_Hash_Table *table)
5959 for (ptrdiff_t i = 0; i < nvalues; i++) 5959 for (ptrdiff_t i = 0; i < nvalues; i++)
5960 pure->key_and_value[i] = purecopy (table->key_and_value[i]); 5960 pure->key_and_value[i] = purecopy (table->key_and_value[i]);
5961 5961
5962 ptrdiff_t index_bytes = table->index_size * sizeof *table->index; 5962 ptrdiff_t index_bytes = hash_table_index_size (table)
5963 * sizeof *table->index;
5963 pure->index = pure_alloc (index_bytes, -(int)sizeof *table->index); 5964 pure->index = pure_alloc (index_bytes, -(int)sizeof *table->index);
5964 memcpy (pure->index, table->index, index_bytes); 5965 memcpy (pure->index, table->index, index_bytes);
5965 } 5966 }