summaryrefslogtreecommitdiff
path: root/src/fns.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-12-28 19:04:43 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2024-01-12 18:03:02 +0100
commit29e3d1c56f07a53d1955c9a71e68f70f3b901728 (patch)
tree8af3a2032f9e99368dd2a4ac14bacc26be23d9ea /src/fns.c
parent484e04efa4fcb81968cba8e05835812c62856287 (diff)
downloademacs-29e3d1c56f07a53d1955c9a71e68f70f3b901728.tar.gz
Abstract predicate and constant for unused hash keys
Qunbound is used for many things; using a predicate and constant for the specific purpose of unused hash entry keys allows us to locate them and make changes much more easily. * src/lisp.h (HASH_UNUSED_ENTRY_KEY, hash_unused_entry_key_p): New constant and function. * src/comp.c (compile_function, Fcomp__compile_ctxt_to_file): * src/composite.c (composition_gstring_cache_clear_font): * src/emacs-module.c (module_global_reference_p): * src/fns.c (make_hash_table, maybe_resize_hash_table, hash_put) (hash_remove_from_table, hash_clear, sweep_weak_table, Fmaphash): * src/json.c (lisp_to_json_nonscalar_1): * src/minibuf.c (Ftry_completion, Fall_completions, Ftest_completion): * src/print.c (print, print_object): Use them.
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/fns.c b/src/fns.c
index 56b4e9a18c0..d8da8992ce9 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4575,7 +4575,7 @@ make_hash_table (struct hash_table_test test, EMACS_INT size,
h->rehash_threshold = rehash_threshold;
h->rehash_size = rehash_size;
h->count = 0;
- h->key_and_value = make_vector (2 * size, Qunbound);
+ h->key_and_value = make_vector (2 * size, HASH_UNUSED_ENTRY_KEY);
h->hash = make_nil_vector (size);
h->next = make_vector (size, make_fixnum (-1));
h->index = make_vector (hash_index_size (h, size), make_fixnum (-1));
@@ -4678,7 +4678,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
Lisp_Object key_and_value
= alloc_larger_vector (h->key_and_value, 2 * new_size);
for (ptrdiff_t i = 2 * old_size; i < 2 * new_size; i++)
- ASET (key_and_value, i, Qunbound);
+ ASET (key_and_value, i, HASH_UNUSED_ENTRY_KEY);
Lisp_Object hash = alloc_larger_vector (h->hash, new_size);
memclear (XVECTOR (hash)->contents + old_size,
@@ -4782,7 +4782,7 @@ hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value,
/* Store key/value in the key_and_value vector. */
ptrdiff_t i = h->next_free;
eassert (NILP (HASH_HASH (h, i)));
- eassert (BASE_EQ (Qunbound, (HASH_KEY (h, i))));
+ eassert (hash_unused_entry_key_p (HASH_KEY (h, i)));
h->next_free = HASH_NEXT (h, i);
set_hash_key_slot (h, i, key);
set_hash_value_slot (h, i, value);
@@ -4824,7 +4824,7 @@ hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
/* Clear slots in key_and_value and add the slots to
the free list. */
- set_hash_key_slot (h, i, Qunbound);
+ set_hash_key_slot (h, i, HASH_UNUSED_ENTRY_KEY);
set_hash_value_slot (h, i, Qnil);
set_hash_hash_slot (h, i, Qnil);
set_hash_next_slot (h, i, h->next_free);
@@ -4851,7 +4851,7 @@ hash_clear (struct Lisp_Hash_Table *h)
for (ptrdiff_t i = 0; i < size; i++)
{
set_hash_next_slot (h, i, i < size - 1 ? i + 1 : -1);
- set_hash_key_slot (h, i, Qunbound);
+ set_hash_key_slot (h, i, HASH_UNUSED_ENTRY_KEY);
set_hash_value_slot (h, i, Qnil);
}
@@ -4922,7 +4922,7 @@ sweep_weak_table (struct Lisp_Hash_Table *h, bool remove_entries_p)
h->next_free = i;
/* Clear key, value, and hash. */
- set_hash_key_slot (h, i, Qunbound);
+ set_hash_key_slot (h, i, HASH_UNUSED_ENTRY_KEY);
set_hash_value_slot (h, i, Qnil);
if (!NILP (h->hash))
set_hash_hash_slot (h, i, Qnil);
@@ -5535,7 +5535,7 @@ FUNCTION is called with two arguments, KEY and VALUE.
for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
{
Lisp_Object k = HASH_KEY (h, i);
- if (!BASE_EQ (k, Qunbound))
+ if (!hash_unused_entry_key_p (k))
call2 (function, k, HASH_VALUE (h, i));
}