aboutsummaryrefslogtreecommitdiffstats
path: root/src/lisp.h
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-01-10 11:50:19 +0100
committerMattias EngdegÄrd2024-01-12 15:06:14 +0100
commit8ec0e030b661ae50d1aef4723b4e83a03645e4ee (patch)
tree013ed1d65639596d06143173991250fc4a0e3af6 /src/lisp.h
parent8884720dce883142965a958fc5a33071388ec2e1 (diff)
downloademacs-scratch/hash-table-perf.tar.gz
emacs-scratch/hash-table-perf.zip
Combine hash and next vector into a single arrayscratch/hash-table-perf
This shrinks the hash object by one word and should give better locality since these values are often accessed at the same time.
Diffstat (limited to 'src/lisp.h')
-rw-r--r--src/lisp.h22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/lisp.h b/src/lisp.h
index 64e8e0c11c3..30e452ffbb0 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2429,6 +2429,11 @@ typedef enum {
2429 (hash) indices. It's signed and a subtype of ptrdiff_t. */ 2429 (hash) indices. It's signed and a subtype of ptrdiff_t. */
2430typedef int32_t hash_idx_t; 2430typedef int32_t hash_idx_t;
2431 2431
2432struct hash_next {
2433 hash_hash_t hash; /* Hash value for entry. Undefined for unused entries. */
2434 hash_idx_t next; /* Next index in bucket or free list, or -1 if last. */
2435};
2436
2432struct Lisp_Hash_Table 2437struct Lisp_Hash_Table
2433{ 2438{
2434 union vectorlike_header header; 2439 union vectorlike_header header;
@@ -2455,11 +2460,11 @@ struct Lisp_Hash_Table
2455 | 2460 |
2456 next_free 2461 next_free
2457 2462
2458 The table is physically split into three vectors (hash, next, 2463 The table is physically split into two vectors (hash_next,
2459 key_and_value) which may or may not be beneficial. */ 2464 key_and_value) which may or may not be beneficial. */
2460 2465
2461 hash_idx_t index_size; /* Size of the index vector. */ 2466 hash_idx_t index_size; /* Size of the index vector. */
2462 hash_idx_t table_size; /* Size of the next and hash vectors. */ 2467 hash_idx_t table_size; /* Size of hash_next and key_and_value arrays. */
2463 2468
2464 /* Bucket vector. An entry of -1 indicates no item is present, 2469 /* Bucket vector. An entry of -1 indicates no item is present,
2465 and a nonnegative entry is the index of the first item in 2470 and a nonnegative entry is the index of the first item in
@@ -2470,9 +2475,9 @@ struct Lisp_Hash_Table
2470 Otherwise it is heap-allocated. */ 2475 Otherwise it is heap-allocated. */
2471 hash_idx_t *index; 2476 hash_idx_t *index;
2472 2477
2473 /* Vector of hash codes. Unused entries have undefined values. 2478 /* Vector of hash values and next indices.
2474 This vector is table_size entries long. */ 2479 This vector is table_size entries long. */
2475 hash_hash_t *hash; 2480 struct hash_next *hash_next;
2476 2481
2477 /* Vector of keys and values. The key of item I is found at index 2482 /* Vector of keys and values. The key of item I is found at index
2478 2 * I, the value is found at index 2 * I + 1. 2483 2 * I, the value is found at index 2 * I + 1.
@@ -2484,13 +2489,6 @@ struct Lisp_Hash_Table
2484 /* The comparison and hash functions. */ 2489 /* The comparison and hash functions. */
2485 const struct hash_table_test *test; 2490 const struct hash_table_test *test;
2486 2491
2487 /* Vector used to chain entries. If entry I is free, next[I] is the
2488 entry number of the next free item. If entry I is non-free,
2489 next[I] is the index of the next entry in the collision chain,
2490 or -1 if there is no such entry.
2491 This vector is table_size entries long. */
2492 hash_idx_t *next;
2493
2494 /* Number of key/value entries in the table. */ 2492 /* Number of key/value entries in the table. */
2495 hash_idx_t count; 2493 hash_idx_t count;
2496 2494
@@ -2565,7 +2563,7 @@ INLINE hash_hash_t
2565HASH_HASH (const struct Lisp_Hash_Table *h, ptrdiff_t idx) 2563HASH_HASH (const struct Lisp_Hash_Table *h, ptrdiff_t idx)
2566{ 2564{
2567 eassert (idx >= 0 && idx < h->table_size); 2565 eassert (idx >= 0 && idx < h->table_size);
2568 return h->hash[idx]; 2566 return h->hash_next[idx].hash;
2569} 2567}
2570 2568
2571/* Value is the size of hash table H. */ 2569/* Value is the size of hash table H. */