[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 3869944bb4f 2/5: Speed up sxhash-equal-including-properties
From: |
Mattias Engdegård |
Subject: |
master 3869944bb4f 2/5: Speed up sxhash-equal-including-properties |
Date: |
Sun, 14 Jan 2024 08:17:49 -0500 (EST) |
branch: master
commit 3869944bb4f9434e0c49063a291ed8a0a33cba50
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Speed up sxhash-equal-including-properties
This function now no longer conses at all. Previously, it constructed
a list structure of all string intervals for the sole purpose of
hashing.
* src/fns.c (hash_interval): New.
(Fsxhash_equal_including_properties):
Use it instead of collect_interval.
---
src/fns.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index f7c36aacea6..07bb5115b6c 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -5240,6 +5240,17 @@ sxhash_obj (Lisp_Object obj, int depth)
}
}
+static void
+hash_interval (INTERVAL interval, void *arg)
+{
+ EMACS_UINT *phash = arg;
+ EMACS_UINT hash = *phash;
+ hash = sxhash_combine (hash, interval->position);
+ hash = sxhash_combine (hash, LENGTH (interval));
+ hash = sxhash_combine (hash, sxhash_obj (interval->plist, 0));
+ *phash = hash;
+}
+
static void
collect_interval (INTERVAL interval, void *arg)
{
@@ -5310,14 +5321,9 @@ Hash codes are not guaranteed to be preserved across
Emacs sessions. */)
{
if (STRINGP (obj))
{
- /* FIXME: This is very wasteful. We needn't cons at all. */
- Lisp_Object collector = Qnil;
- traverse_intervals (string_intervals (obj), 0, collect_interval,
- &collector);
- return
- make_ufixnum (
- SXHASH_REDUCE (sxhash_combine (sxhash (obj),
- sxhash (collector))));
+ EMACS_UINT hash = 0;
+ traverse_intervals (string_intervals (obj), 0, hash_interval, &hash);
+ return make_ufixnum (SXHASH_REDUCE (sxhash_combine (sxhash (obj),
hash)));
}
return hash_hash_to_fixnum (hashfn_equal (obj, NULL));