emacs-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]