aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-01-14 12:33:12 +0100
committerMattias EngdegÄrd2024-01-14 14:17:41 +0100
commit3869944bb4f9434e0c49063a291ed8a0a33cba50 (patch)
tree7d513c624b4e760c0fedf06cbb55e484fb030276 /src
parenta9cee9c6675a7002441bdd186402f45eb5379172 (diff)
downloademacs-3869944bb4f9434e0c49063a291ed8a0a33cba50.tar.gz
emacs-3869944bb4f9434e0c49063a291ed8a0a33cba50.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c22
1 files 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
@@ -5241,6 +5241,17 @@ sxhash_obj (Lisp_Object obj, int depth)
5241} 5241}
5242 5242
5243static void 5243static void
5244hash_interval (INTERVAL interval, void *arg)
5245{
5246 EMACS_UINT *phash = arg;
5247 EMACS_UINT hash = *phash;
5248 hash = sxhash_combine (hash, interval->position);
5249 hash = sxhash_combine (hash, LENGTH (interval));
5250 hash = sxhash_combine (hash, sxhash_obj (interval->plist, 0));
5251 *phash = hash;
5252}
5253
5254static void
5244collect_interval (INTERVAL interval, void *arg) 5255collect_interval (INTERVAL interval, void *arg)
5245{ 5256{
5246 Lisp_Object *collector = arg; 5257 Lisp_Object *collector = arg;
@@ -5310,14 +5321,9 @@ Hash codes are not guaranteed to be preserved across Emacs sessions. */)
5310{ 5321{
5311 if (STRINGP (obj)) 5322 if (STRINGP (obj))
5312 { 5323 {
5313 /* FIXME: This is very wasteful. We needn't cons at all. */ 5324 EMACS_UINT hash = 0;
5314 Lisp_Object collector = Qnil; 5325 traverse_intervals (string_intervals (obj), 0, hash_interval, &hash);
5315 traverse_intervals (string_intervals (obj), 0, collect_interval, 5326 return make_ufixnum (SXHASH_REDUCE (sxhash_combine (sxhash (obj), hash)));
5316 &collector);
5317 return
5318 make_ufixnum (
5319 SXHASH_REDUCE (sxhash_combine (sxhash (obj),
5320 sxhash (collector))));
5321 } 5327 }
5322 5328
5323 return hash_hash_to_fixnum (hashfn_equal (obj, NULL)); 5329 return hash_hash_to_fixnum (hashfn_equal (obj, NULL));