[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/hash-table-perf 310f6584ccb 18/37: Allow zero hash table size
From: |
Mattias Engdegård |
Subject: |
scratch/hash-table-perf 310f6584ccb 18/37: Allow zero hash table size |
Date: |
Sun, 7 Jan 2024 12:41:14 -0500 (EST) |
branch: scratch/hash-table-perf
commit 310f6584ccb37b6d1aa8f2fc9a06f41157cf5160
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Allow zero hash table size
This avoids any extra allocation for such vectors, including empty
tables read by the Lisp reader, and provides extra safety essentially
for free.
* src/fns.c (make_hash_table): Allow tables to be 0-sized. The index
will always have at least one entry, to avoid extra look-up costs.
* src/alloc.c (process_mark_stack): Don't mark pure objects,
because empty vectors are pure.
---
src/alloc.c | 3 ++-
src/fns.c | 7 +++----
src/lisp.h | 4 +---
3 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index be20dc6e5e7..0107e8dd925 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -7272,7 +7272,8 @@ process_mark_stack (ptrdiff_t base_sp)
eassert (h->next_weak == NULL);
h->next_weak = weak_hash_tables;
weak_hash_tables = h;
- set_vector_marked (XVECTOR (h->key_and_value));
+ if (!PURE_P (h->key_and_value))
+ set_vector_marked (XVECTOR (h->key_and_value));
}
break;
}
diff --git a/src/fns.c b/src/fns.c
index db2b5fdb5cc..be7def86c62 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4555,9 +4555,6 @@ make_hash_table (struct hash_table_test test, EMACS_INT
size,
eassert (SYMBOLP (test.name));
eassert (0 <= size && size <= MOST_POSITIVE_FIXNUM);
- if (size == 0)
- size = 1;
-
/* Allocate a table and initialize it. */
h = allocate_hash_table ();
@@ -4576,7 +4573,9 @@ make_hash_table (struct hash_table_test test, EMACS_INT
size,
/* Set up the free list. */
for (i = 0; i < size - 1; ++i)
set_hash_next_slot (h, i, i + 1);
- h->next_free = 0;
+ if (size > 0)
+ set_hash_next_slot (h, size - 1, -1);
+ h->next_free = size > 0 ? 0 : -1;
XSET_HASH_TABLE (table, h);
eassert (HASH_TABLE_P (table));
diff --git a/src/lisp.h b/src/lisp.h
index 1f3220c0179..215e72ca2c9 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2538,9 +2538,7 @@ HASH_HASH (const struct Lisp_Hash_Table *h, ptrdiff_t idx)
INLINE ptrdiff_t
HASH_TABLE_SIZE (const struct Lisp_Hash_Table *h)
{
- ptrdiff_t size = ASIZE (h->next);
- eassume (0 < size);
- return size;
+ return ASIZE (h->next);
}
/* Compute hash value for KEY in hash table H. */
- scratch/hash-table-perf c188b9f2bf5 08/37: Refactor hash table vector reallocation, (continued)
- 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, 2024/01/07
- 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 <=
- 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
- scratch/hash-table-perf 5cf627d70e1 30/37: Don't dump Qunbound, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 8b1b140bed9 32/37: * src/lisp.h (hash_hash_t): Change to uint32_t., Mattias Engdegård, 2024/01/07