[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/hash-table-perf 1ebd00f6d0a 21/37: Retype hash interfaces to use
From: |
Mattias Engdegård |
Subject: |
scratch/hash-table-perf 1ebd00f6d0a 21/37: Retype hash interfaces to use EMACS_UINT instead of Lisp fixnum |
Date: |
Sun, 7 Jan 2024 12:41:16 -0500 (EST) |
branch: scratch/hash-table-perf
commit 1ebd00f6d0a19986ba3cdc833ca378cbd33ad936
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Retype hash interfaces to use EMACS_UINT instead of Lisp fixnum
This eliminates some useless tagging and untagging.
* src/lisp.h (struct hash_table_test): `hashfn` now returns
EMACS_UINT. All callers and implementations changed.
* src/fns.c (hash_lookup, hash_put): Hash value arguments retyped
as EMACS_UINT. All callers changed.
---
src/category.c | 2 +-
src/charset.c | 2 +-
src/composite.c | 5 +++--
src/emacs-module.c | 3 ++-
src/fns.c | 49 ++++++++++++++++++++++++-------------------------
src/image.c | 3 ++-
src/json.c | 3 ++-
src/lisp.h | 8 ++++----
src/lread.c | 8 ++++----
src/macfont.m | 3 ++-
10 files changed, 45 insertions(+), 41 deletions(-)
diff --git a/src/category.c b/src/category.c
index fe07c11fdee..855db5cd86c 100644
--- a/src/category.c
+++ b/src/category.c
@@ -53,7 +53,7 @@ hash_get_category_set (Lisp_Object table, Lisp_Object
category_set)
(table, 1,
make_hash_table (hashtest_equal, DEFAULT_HASH_SIZE, Weak_None, false));
struct Lisp_Hash_Table *h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, category_set, &hash);
if (i >= 0)
return HASH_KEY (h, i);
diff --git a/src/charset.c b/src/charset.c
index d5e42d038df..e3e3b8e8757 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -850,7 +850,6 @@ usage: (define-charset-internal ...) */)
/* Charset attr vector. */
Lisp_Object attrs;
Lisp_Object val;
- Lisp_Object hash_code;
struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table);
int i, j;
struct charset charset;
@@ -1108,6 +1107,7 @@ usage: (define-charset-internal ...) */)
CHECK_LIST (args[charset_arg_plist]);
ASET (attrs, charset_plist, args[charset_arg_plist]);
+ EMACS_UINT hash_code;
charset.hash_index = hash_lookup (hash_table, args[charset_arg_name],
&hash_code);
if (charset.hash_index >= 0)
diff --git a/src/composite.c b/src/composite.c
index f9cf17770dc..035607c73ff 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -166,7 +166,7 @@ ptrdiff_t
get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
Lisp_Object prop, Lisp_Object string)
{
- Lisp_Object id, length, components, key, *key_contents, hash_code;
+ Lisp_Object id, length, components, key, *key_contents;
ptrdiff_t glyph_len;
struct Lisp_Hash_Table *hash_table = XHASH_TABLE (composition_hash_table);
ptrdiff_t hash_index;
@@ -240,6 +240,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos,
ptrdiff_t nchars,
else
goto invalid_composition;
+ EMACS_UINT hash_code;
hash_index = hash_lookup (hash_table, key, &hash_code);
if (hash_index >= 0)
{
@@ -653,7 +654,7 @@ composition_gstring_put_cache (Lisp_Object gstring,
ptrdiff_t len)
{
struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
Lisp_Object header = LGSTRING_HEADER (gstring);
- Lisp_Object hash = hash_from_key (h, header);
+ EMACS_UINT hash = hash_from_key (h, header);
if (len < 0)
{
ptrdiff_t glyph_len = LGSTRING_GLYPH_LEN (gstring);
diff --git a/src/emacs-module.c b/src/emacs-module.c
index c7d2a6974e8..a29c2c62155 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -427,7 +427,8 @@ module_make_global_ref (emacs_env *env, emacs_value value)
{
MODULE_FUNCTION_BEGIN (NULL);
struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash);
- Lisp_Object new_obj = value_to_lisp (value), hashcode;
+ Lisp_Object new_obj = value_to_lisp (value);
+ EMACS_UINT hashcode;
ptrdiff_t i = hash_lookup (h, new_obj, &hashcode);
/* Note: This approach requires the garbage collector to never move
diff --git a/src/fns.c b/src/fns.c
index 9d4f1b4d4d9..56798e009d5 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2759,7 +2759,7 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum
equal_kind equal_kind,
case Lisp_Cons: case Lisp_Vectorlike:
{
struct Lisp_Hash_Table *h = XHASH_TABLE (ht);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, o1, &hash);
if (i >= 0)
{ /* `o1' was seen already. */
@@ -4450,41 +4450,42 @@ cmpfn_user_defined (Lisp_Object key1, Lisp_Object key2,
/* Ignore H and return a hash code for KEY which uses 'eq' to compare keys. */
-static Lisp_Object
+static EMACS_UINT
hashfn_eq (Lisp_Object key, struct Lisp_Hash_Table *h)
{
if (symbols_with_pos_enabled && SYMBOL_WITH_POS_P (key))
key = SYMBOL_WITH_POS_SYM (key);
- return make_ufixnum (XHASH (key) ^ XTYPE (key));
+ return XHASH (key) ^ XTYPE (key);
}
/* Ignore H and return a hash code for KEY which uses 'equal' to compare keys.
The hash code is at most INTMASK. */
-static Lisp_Object
+static EMACS_UINT
hashfn_equal (Lisp_Object key, struct Lisp_Hash_Table *h)
{
- return make_ufixnum (sxhash (key));
+ return sxhash (key);
}
/* Ignore H and return a hash code for KEY which uses 'eql' to compare keys.
The hash code is at most INTMASK. */
-static Lisp_Object
+static EMACS_UINT
hashfn_eql (Lisp_Object key, struct Lisp_Hash_Table *h)
{
- return (FLOATP (key) || BIGNUMP (key) ? hashfn_equal : hashfn_eq) (key, h);
+ return (FLOATP (key) || BIGNUMP (key)
+ ? hashfn_equal (key, h) : hashfn_eq (key, h));
}
/* Given H, return a hash code for KEY which uses a user-defined
function to compare keys. */
-static Lisp_Object
+static EMACS_UINT
hashfn_user_defined (Lisp_Object key, struct Lisp_Hash_Table *h)
{
Lisp_Object args[] = { h->test.user_hash_function, key };
Lisp_Object hash = hash_table_user_defined_call (ARRAYELTS (args), args, h);
- return FIXNUMP (hash) ? hash : make_ufixnum (sxhash (hash));
+ return FIXNUMP (hash) ? XUFIXNUM(hash) : sxhash (hash);
}
struct hash_table_test const
@@ -4765,7 +4766,7 @@ hash_table_thaw (Lisp_Object hash_table)
for (ptrdiff_t i = 0; i < size; i++)
{
Lisp_Object key = HASH_KEY (h, i);
- EMACS_UINT hash_code = XUFIXNUM (hash_from_key (h, key));
+ EMACS_UINT hash_code = hash_from_key (h, key);
ptrdiff_t start_of_bucket = hash_index_index (h, hash_code);
set_hash_hash_slot (h, i, hash_code);
set_hash_next_slot (h, i, HASH_INDEX (h, start_of_bucket));
@@ -4778,19 +4779,18 @@ hash_table_thaw (Lisp_Object hash_table)
matching KEY, or -1 if not found. */
ptrdiff_t
-hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object *hash)
+hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash)
{
- Lisp_Object hash_code = hash_from_key (h, key);
+ EMACS_UINT hash_code = hash_from_key (h, key);
if (hash)
*hash = hash_code;
- EMACS_UINT hashval = XUFIXNUM (hash_code);
- ptrdiff_t start_of_bucket = hash_index_index (h, hashval);
+ ptrdiff_t start_of_bucket = hash_index_index (h, hash_code);
ptrdiff_t i;
for (i = HASH_INDEX (h, start_of_bucket); 0 <= i; i = HASH_NEXT (h, i))
if (EQ (key, HASH_KEY (h, i))
|| (h->test.cmpfn
- && hashval == HASH_HASH (h, i)
+ && hash_code == HASH_HASH (h, i)
&& !NILP (h->test.cmpfn (key, HASH_KEY (h, i), h))))
break;
@@ -4811,7 +4811,7 @@ check_mutable_hash_table (Lisp_Object obj, struct
Lisp_Hash_Table *h)
ptrdiff_t
hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value,
- Lisp_Object hash)
+ EMACS_UINT hash)
{
/* Increment count after resizing because resizing may fail. */
maybe_resize_hash_table (h);
@@ -4826,11 +4826,10 @@ hash_put (struct Lisp_Hash_Table *h, Lisp_Object key,
Lisp_Object value,
set_hash_value_slot (h, i, value);
/* Remember its hash code. */
- EMACS_UINT hashval = XUFIXNUM (hash);
- set_hash_hash_slot (h, i, hashval);
+ set_hash_hash_slot (h, i, hash);
/* Add new entry to its collision chain. */
- ptrdiff_t start_of_bucket = hash_index_index (h, hashval);
+ ptrdiff_t start_of_bucket = hash_index_index (h, hash);
set_hash_next_slot (h, i, HASH_INDEX (h, start_of_bucket));
set_hash_index_slot (h, start_of_bucket, i);
return i;
@@ -4842,7 +4841,7 @@ hash_put (struct Lisp_Hash_Table *h, Lisp_Object key,
Lisp_Object value,
void
hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
{
- EMACS_UINT hashval = XUFIXNUM (hash_from_key (h, key));
+ EMACS_UINT hashval = hash_from_key (h, key);
ptrdiff_t start_of_bucket = hash_index_index (h, hashval);
ptrdiff_t prev = -1;
@@ -5257,7 +5256,7 @@ If (eq A B), then (= (sxhash-eq A) (sxhash-eq B)).
Hash codes are not guaranteed to be preserved across Emacs sessions. */)
(Lisp_Object obj)
{
- return hashfn_eq (obj, NULL);
+ return make_ufixnum (hashfn_eq (obj, NULL));
}
DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0,
@@ -5268,7 +5267,7 @@ isn't necessarily true.
Hash codes are not guaranteed to be preserved across Emacs sessions. */)
(Lisp_Object obj)
{
- return hashfn_eql (obj, NULL);
+ return make_ufixnum (hashfn_eql (obj, NULL));
}
DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0,
@@ -5279,7 +5278,7 @@ opposite isn't necessarily true.
Hash codes are not guaranteed to be preserved across Emacs sessions. */)
(Lisp_Object obj)
{
- return hashfn_equal (obj, NULL);
+ return make_ufixnum (hashfn_equal (obj, NULL));
}
DEFUN ("sxhash-equal-including-properties", Fsxhash_equal_including_properties,
@@ -5303,7 +5302,7 @@ Hash codes are not guaranteed to be preserved across
Emacs sessions. */)
sxhash (CDR (collector)))));
}
- return hashfn_equal (obj, NULL);
+ return make_ufixnum (hashfn_equal (obj, NULL));
}
DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0,
@@ -5537,7 +5536,7 @@ VALUE. In any case, return VALUE. */)
struct Lisp_Hash_Table *h = check_hash_table (table);
check_mutable_hash_table (table, h);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, key, &hash);
if (i >= 0)
set_hash_value_slot (h, i, value);
diff --git a/src/image.c b/src/image.c
index ad1b80fa97e..4fb5a9e6ccc 100644
--- a/src/image.c
+++ b/src/image.c
@@ -6079,8 +6079,9 @@ xpm_put_color_table_h (Lisp_Object color_table,
Lisp_Object color)
{
struct Lisp_Hash_Table *table = XHASH_TABLE (color_table);
- Lisp_Object chars = make_unibyte_string (chars_start, chars_len), hash_code;
+ Lisp_Object chars = make_unibyte_string (chars_start, chars_len);
+ EMACS_UINT hash_code;
hash_lookup (table, chars, &hash_code);
hash_put (table, chars, color, hash_code);
}
diff --git a/src/json.c b/src/json.c
index de9bac41e52..53add86bfc1 100644
--- a/src/json.c
+++ b/src/json.c
@@ -879,7 +879,8 @@ json_to_lisp (json_t *json, const struct json_configuration
*conf)
json_t *value;
json_object_foreach (json, key_str, value)
{
- Lisp_Object key = build_string_from_utf8 (key_str), hash;
+ Lisp_Object key = build_string_from_utf8 (key_str);
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, key, &hash);
/* Keys in JSON objects are unique, so the key can't
be present yet. */
diff --git a/src/lisp.h b/src/lisp.h
index d8af923263b..e842a1a5b29 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2406,7 +2406,7 @@ struct hash_table_test
Lisp_Object (*cmpfn) (Lisp_Object, Lisp_Object, struct Lisp_Hash_Table *);
/* C function to compute hash code. */
- Lisp_Object (*hashfn) (Lisp_Object, struct Lisp_Hash_Table *);
+ EMACS_UINT (*hashfn) (Lisp_Object, struct Lisp_Hash_Table *);
};
typedef enum {
@@ -2548,7 +2548,7 @@ HASH_TABLE_SIZE (const struct Lisp_Hash_Table *h)
}
/* Compute hash value for KEY in hash table H. */
-INLINE Lisp_Object
+INLINE EMACS_UINT
hash_from_key (struct Lisp_Hash_Table *h, Lisp_Object key)
{
return h->test.hashfn (key, h);
@@ -4001,9 +4001,9 @@ EMACS_UINT sxhash (Lisp_Object);
Lisp_Object make_hash_table (struct hash_table_test, EMACS_INT,
hash_table_weakness_t, bool);
Lisp_Object hash_table_weakness_symbol (hash_table_weakness_t weak);
-ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object *);
+ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
- Lisp_Object);
+ EMACS_UINT);
void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object);
extern struct hash_table_test const hashtest_eq, hashtest_eql, hashtest_equal;
extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
diff --git a/src/lread.c b/src/lread.c
index bdd8239afe0..b03b7575552 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -4255,7 +4255,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
struct Lisp_Hash_Table *h
= XHASH_TABLE (read_objects_map);
Lisp_Object number = make_fixnum (n);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, number, &hash);
if (i >= 0)
/* Not normal, but input could be malformed. */
@@ -4571,7 +4571,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
struct Lisp_Hash_Table *h2
= XHASH_TABLE (read_objects_completed);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h2, placeholder, &hash);
eassert (i < 0);
hash_put (h2, placeholder, Qnil, hash);
@@ -4586,7 +4586,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
{
struct Lisp_Hash_Table *h2
= XHASH_TABLE (read_objects_completed);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h2, obj, &hash);
eassert (i < 0);
hash_put (h2, obj, Qnil, hash);
@@ -4598,7 +4598,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
/* ...and #n# will use the real value from now on. */
struct Lisp_Hash_Table *h = XHASH_TABLE (read_objects_map);
- Lisp_Object hash;
+ EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, e->u.numbered.number, &hash);
eassert (i >= 0);
set_hash_value_slot (h, i, obj);
diff --git a/src/macfont.m b/src/macfont.m
index ea8cd2413d0..1f050b16805 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -1017,12 +1017,13 @@ macfont_set_family_cache (Lisp_Object symbol,
CFStringRef string)
{
struct Lisp_Hash_Table *h;
ptrdiff_t i;
- Lisp_Object hash, value;
+ Lisp_Object value;
if (!HASH_TABLE_P (macfont_family_cache))
macfont_family_cache = CALLN (Fmake_hash_table, QCtest, Qeq);
h = XHASH_TABLE (macfont_family_cache);
+ EMACS_UINT hash;
i = hash_lookup (h, symbol, &hash);
value = string ? make_mint_ptr ((void *) CFRetain (string)) : Qnil;
if (i >= 0)
- scratch/hash-table-perf 6ffbccbf1dd 15/37: Represent hash table weakness as an enum internally, (continued)
- 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, 2024/01/07
- 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 <=
- 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
- scratch/hash-table-perf 830838eb5f3 31/37: Use KEY=Qunbound instead of HASH=hash_unused for unused entries, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 05297736aa6 33/37: Adapt hash functions to produce a hash_hash_t eventually, Mattias Engdegård, 2024/01/07