emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0a998938ca1 11/20: Use hash_idx_t for storing hash indices


From: Mattias Engdegård
Subject: master 0a998938ca1 11/20: Use hash_idx_t for storing hash indices
Date: Sat, 13 Jan 2024 14:54:01 -0500 (EST)

branch: master
commit 0a998938ca1b7e5e6f09d14b4a62ec7089be2af6
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     |  8 ++++----
 src/lisp.h    | 18 +++++++++++-------
 src/pdumper.c |  2 +-
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/fns.c b/src/fns.c
index 9d802bba0e2..c4e7a98a4d3 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4539,7 +4539,7 @@ hash_index_size (ptrdiff_t size)
 
 /* Constant hash index vector used when the table size is zero.
    This avoids allocating it from the heap.  */
-static const ptrdiff_t empty_hash_index_vector[] = {-1};
+static const hash_idx_t empty_hash_index_vector[] = {-1};
 
 /* Create and initialize a new hash table.
 
@@ -4578,7 +4578,7 @@ make_hash_table (struct hash_table_test test, EMACS_INT 
size,
       h->hash = NULL;
       h->next = NULL;
       eassert (index_size == 1);
-      h->index = (ptrdiff_t *)empty_hash_index_vector;
+      h->index = (hash_idx_t *)empty_hash_index_vector;
       h->next_free = -1;
     }
   else
@@ -4684,7 +4684,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);
       for (ptrdiff_t i = old_size; i < new_size - 1; i++)
        next[i] = i + 1;
       next[new_size - 1] = -1;
@@ -4703,7 +4703,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 02d9c98da22..33c1e345f7a 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2430,6 +2430,10 @@ typedef enum {
 enum { hash_unused = (hash_hash_t)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
 {
   union vectorlike_header header;
@@ -2459,6 +2463,9 @@ struct Lisp_Hash_Table
      The table is physically split into three vectors (hash, next,
      key_and_value) which may or may not be beneficial.  */
 
+  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.
@@ -2466,10 +2473,7 @@ struct Lisp_Hash_Table
      If index_size is 1 (and table_size is 0), then this is the
      constant read-only vector {-1}, shared between all instances.
      Otherwise it is heap-allocated.  */
-  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.  */
@@ -2480,13 +2484,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 5ed91c668df..6b053c5b601 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]