[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/hash-table-perf b1218be258a 18/35: Allow zero hash table size
From: |
Mattias Engdegård |
Subject: |
scratch/hash-table-perf b1218be258a 18/35: Allow zero hash table size |
Date: |
Fri, 12 Jan 2024 10:53:25 -0500 (EST) |
branch: scratch/hash-table-perf
commit b1218be258ab4dda0f6815899b8e33e66c02a73c
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 95eeb6afe9b..386fc40bf3d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2560,9 +2560,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. */
- branch scratch/hash-table-perf created (now 8ec0e030b66), Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf a39bca66533 03/35: Decouple profiler from Lisp hash table internals, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf dd89a9fb76d 04/35: Refactor: less layering violation in composite.h, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 05694f4491d 08/35: ; * src/alloc.c (purecopy_hash_table): Simplify, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf b9b2c5a12a8 10/35: ; * src/fns.c (Fmake_hash_table): ensure `test` is a bare symbol, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf b96f48232ac 11/35: ; * src/lisp.h (struct Lisp_Hash_Table): Add ASCII art., Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf d7dbbc74a00 13/35: * src/print.c (print_object): Don't print empty hash-table data, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 9b39cee78e3 12/35: * src/print.c (print_object): Don't print hash table test if `eql`., Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 08acca67739 14/35: Don't print or read the hash table size parameter, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf b1218be258a 18/35: Allow zero hash table size,
Mattias Engdegård <=
- scratch/hash-table-perf 8f608cb4a1c 28/35: Use key Qunbound instead of hash value hash_unused for free entries, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 93d6326e6c0 32/35: Hash-table documentation updates, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 1462fca6dce 16/35: Remove rehash-threshold and rehash-size struct members, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 3b3fea97ecc 22/35: Use hash_idx_t for storing hash indices, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 58559a83827 29/35: * src/lisp.h (hash_hash_t): Change to uint32_t., Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 441c4d53cf6 31/35: Don't pretend that hash-table-size is useful, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf a0560e90d3b 26/35: Change hash_idx_t to int32_t on all platforms, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf 8ec0e030b66 35/35: Combine hash and next vector into a single array, Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf b9a0b88aea8 05/35: ; * src/fns.c (collect_interval): Move misplaced function., Mattias Engdegård, 2024/01/12
- scratch/hash-table-perf ed4ce0af9a9 06/35: Refactor: extract hash and index computations to functions, Mattias Engdegård, 2024/01/12