[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/hash-table-perf 54807fee4d0 23/37: Use hash_idx_t for storing ha
From: |
Mattias Engdegård |
Subject: |
scratch/hash-table-perf 54807fee4d0 23/37: Use hash_idx_t for storing hash indices |
Date: |
Sun, 7 Jan 2024 12:41:18 -0500 (EST) |
branch: scratch/hash-table-perf
commit 54807fee4d0d839ab70d5b1b86d6c1f9ceeda55e
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Use hash_idx_t for storing hash indices
Now hash_idx_t is a typedef for ptrdiff_t so there is no actual code
change, but this allows us to decouple the index width from the Lisp
word size.
* src/lisp.h (hash_idx_t): New typedef for ptrdiff_t.
(struct Lisp_Hash_Table): Use it for indices and sizes:
index, next, table_size, index_size, count and next_free.
All uses adapted.
---
src/fns.c | 4 ++--
src/lisp.h | 18 +++++++++++-------
src/pdumper.c | 2 +-
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index fe446e81a7a..ccd2ade1215 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4666,7 +4666,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
/* Allocate all the new vectors before updating *H, to
avoid problems if memory is exhausted. */
- ptrdiff_t *next = hash_table_alloc_bytes (new_size * sizeof *next);
+ hash_idx_t *next = hash_table_alloc_bytes (new_size * sizeof *next);
memcpy (next, h->next, old_size * sizeof *next);
for (ptrdiff_t i = old_size; i < new_size - 1; i++)
next[i] = i + 1;
@@ -4686,7 +4686,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
ptrdiff_t old_index_size = h->index_size;
ptrdiff_t index_size = hash_index_size (new_size);
- ptrdiff_t *index = hash_table_alloc_bytes (index_size * sizeof *index);
+ hash_idx_t *index = hash_table_alloc_bytes (index_size * sizeof *index);
for (ptrdiff_t i = 0; i < index_size; i++)
index[i] = -1;
diff --git a/src/lisp.h b/src/lisp.h
index f1a650b1424..6ea7ded0fd5 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2426,6 +2426,10 @@ typedef enum {
enum { hash_unused = (EMACS_UINT)MOST_POSITIVE_FIXNUM + 1 };
verify (FIXNUM_OVERFLOW_P (hash_unused));
+/* The type of a hash table index, both for table indices and index
+ (hash) indices. It's signed and a subtype of ptrdiff_t. */
+typedef ptrdiff_t hash_idx_t;
+
struct Lisp_Hash_Table
{
/* Change pdumper.c if you change the fields here. */
@@ -2433,14 +2437,14 @@ struct Lisp_Hash_Table
/* This is for Lisp; the hash table code does not refer to it. */
union vectorlike_header header;
+ hash_idx_t index_size; /* Size of the index vector. */
+ hash_idx_t table_size; /* Size of the next and hash vectors. */
+
/* Bucket vector. An entry of -1 indicates no item is present,
and a nonnegative entry is the index of the first item in
a collision chain. This vector's size can be larger than the
hash table size to reduce collisions. */
- ptrdiff_t *index;
- ptrdiff_t index_size; /* Size of the index vector. */
-
- ptrdiff_t table_size; /* Size of the next and hash vectors. */
+ hash_idx_t *index;
/* Vector of hash codes. The value hash_unused marks an unused table entry.
This vector is table_size entries long. */
@@ -2451,13 +2455,13 @@ struct Lisp_Hash_Table
next[I] is the index of the next entry in the collision chain,
or -1 if there is no such entry.
This vector is table_size entries long. */
- ptrdiff_t *next;
+ hash_idx_t *next;
/* Number of key/value entries in the table. */
- ptrdiff_t count;
+ hash_idx_t count;
/* Index of first free entry in free list, or -1 if none. */
- ptrdiff_t next_free;
+ hash_idx_t next_free;
/* Weakness of the table. */
hash_table_weakness_t weakness : 8;
diff --git a/src/pdumper.c b/src/pdumper.c
index bc31dd8fa6d..5d88f1706eb 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -1226,7 +1226,7 @@ dump_queue_dequeue (struct dump_queue *dump_queue,
dump_off basis)
dump_tailq_length (&dump_queue->zero_weight_objects),
dump_tailq_length (&dump_queue->one_weight_normal_objects),
dump_tailq_length (&dump_queue->one_weight_strong_objects),
- XHASH_TABLE (dump_queue->link_weights)->count);
+ (ptrdiff_t) XHASH_TABLE (dump_queue->link_weights)->count);
static const int nr_candidates = 3;
struct candidate
- scratch/hash-table-perf 4b5d9f92abe 13/37: * src/print.c (print_object): Don't print empty hash-table data, (continued)
- scratch/hash-table-perf 4b5d9f92abe 13/37: * src/print.c (print_object): Don't print empty hash-table data, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 3e9e68333ae 16/37: Remove rehash-threshold and rehash-size struct members, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf c188b9f2bf5 08/37: Refactor hash table vector reallocation, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf fdc390f8dc0 10/37: Abstract predicate and constant for unused hash keys, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 6ffbccbf1dd 15/37: Represent hash table weakness as an enum internally, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e69035c6ef5 17/37: Leaner hash table dumping and thawing, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf f3e985a16ba 14/37: Don't print or read the hash table size parameter, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e2a6ce36d83 03/37: Decouple profiler from Lisp hash table internals, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf c4df6041de8 12/37: * src/print.c (print_object): Don't print hash table test if `eql`., Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 2d28042f56a 19/37: Use non-Lisp allocation for internal hash-table vectors, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 54807fee4d0 23/37: Use hash_idx_t for storing hash indices,
Mattias Engdegård <=
- scratch/hash-table-perf fc68176120f 24/37: Use hash_hash_t for storing hash values, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 310f6584ccb 18/37: Allow zero hash table size, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 8e80d1930e3 20/37: Store hash values as EMACS_UINT instead of Lisp_Object, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 1ebd00f6d0a 21/37: Retype hash interfaces to use EMACS_UINT instead of Lisp fixnum, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 8335891387a 22/37: Inlined and specialised hash table look-up, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf ad3d2f8ed88 25/37: Share hash table test structs, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e53398ab698 26/37: ; Reorder structs (hash and test), Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 1672d880e0c 29/37: Change hash_idx_t to int32_t on all platforms, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e6defe82569 27/37: Change default hash table size to 8 (from 65), Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 41e37c978e6 28/37: Rework index size and resize factor computations, Mattias Engdegård, 2024/01/07