aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrea Corallo2021-04-21 14:22:11 +0200
committerAndrea Corallo2021-04-21 17:36:59 +0200
commit0eee48af9de308ef57a065ecd8b2c2c7b59012a0 (patch)
tree2f8a382f7dc51222438e856ecab5343e5f22184a /src
parentb5c76530fab4b99e76249bfb9a105b30bef4ce67 (diff)
downloademacs-0eee48af9de308ef57a065ecd8b2c2c7b59012a0.tar.gz
emacs-0eee48af9de308ef57a065ecd8b2c2c7b59012a0.zip
Introduce `sxhash-equal-including-properties'.
* src/fns.c (collect_interval): Move it upwards. (Fsxhash_equal_including_properties): New function. (syms_of_fns): Register `sxhash-equal-including-properties'. * etc/NEWS: Add 'sxhash-equal-including-properties'.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/fns.c b/src/fns.c
index 1758148ff2d..41429c8863d 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4492,6 +4492,15 @@ check_mutable_hash_table (Lisp_Object obj, struct Lisp_Hash_Table *h)
4492 eassert (!PURE_P (h)); 4492 eassert (!PURE_P (h));
4493} 4493}
4494 4494
4495static void
4496collect_interval (INTERVAL interval, Lisp_Object collector)
4497{
4498 nconc2 (collector,
4499 list1(list3 (make_fixnum (interval->position),
4500 make_fixnum (interval->position + LENGTH (interval)),
4501 interval->plist)));
4502}
4503
4495/* Put an entry into hash table H that associates KEY with VALUE. 4504/* Put an entry into hash table H that associates KEY with VALUE.
4496 HASH is a previously computed hash code of KEY. 4505 HASH is a previously computed hash code of KEY.
4497 Value is the index of the entry in H matching KEY. */ 4506 Value is the index of the entry in H matching KEY. */
@@ -4949,6 +4958,30 @@ Hash codes are not guaranteed to be preserved across Emacs sessions. */)
4949 return hashfn_equal (obj, NULL); 4958 return hashfn_equal (obj, NULL);
4950} 4959}
4951 4960
4961DEFUN ("sxhash-equal-including-properties", Fsxhash_equal_including_properties,
4962 Ssxhash_equal_including_properties, 1, 1, 0,
4963 doc: /* Return an integer hash code for OBJ suitable for
4964`equal-including-properties'.
4965If (sxhash-equal-including-properties A B), then
4966(= (sxhash-equal-including-properties A) (sxhash-equal-including-properties B)).
4967
4968Hash codes are not guaranteed to be preserved across Emacs sessions. */)
4969 (Lisp_Object obj)
4970{
4971 if (STRINGP (obj))
4972 {
4973 Lisp_Object collector = Fcons (Qnil, Qnil);
4974 traverse_intervals (string_intervals (obj), 0, collect_interval,
4975 collector);
4976 return
4977 make_ufixnum (
4978 SXHASH_REDUCE (sxhash_combine (sxhash (obj),
4979 sxhash (CDR (collector)))));
4980 }
4981
4982 return hashfn_equal (obj, NULL);
4983}
4984
4952DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0, 4985DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0,
4953 doc: /* Create and return a new hash table. 4986 doc: /* Create and return a new hash table.
4954 4987
@@ -5832,15 +5865,6 @@ Case is always significant and text properties are ignored. */)
5832 return make_int (string_byte_to_char (haystack, res - SSDATA (haystack))); 5865 return make_int (string_byte_to_char (haystack, res - SSDATA (haystack)));
5833} 5866}
5834 5867
5835static void
5836collect_interval (INTERVAL interval, Lisp_Object collector)
5837{
5838 nconc2 (collector,
5839 list1(list3 (make_fixnum (interval->position),
5840 make_fixnum (interval->position + LENGTH (interval)),
5841 interval->plist)));
5842}
5843
5844DEFUN ("object-intervals", Fobject_intervals, Sobject_intervals, 1, 1, 0, 5868DEFUN ("object-intervals", Fobject_intervals, Sobject_intervals, 1, 1, 0,
5845 doc: /* Return a copy of the text properties of OBJECT. 5869 doc: /* Return a copy of the text properties of OBJECT.
5846OBJECT must be a buffer or a string. 5870OBJECT must be a buffer or a string.
@@ -5922,6 +5946,7 @@ syms_of_fns (void)
5922 defsubr (&Ssxhash_eq); 5946 defsubr (&Ssxhash_eq);
5923 defsubr (&Ssxhash_eql); 5947 defsubr (&Ssxhash_eql);
5924 defsubr (&Ssxhash_equal); 5948 defsubr (&Ssxhash_equal);
5949 defsubr (&Ssxhash_equal_including_properties);
5925 defsubr (&Smake_hash_table); 5950 defsubr (&Smake_hash_table);
5926 defsubr (&Scopy_hash_table); 5951 defsubr (&Scopy_hash_table);
5927 defsubr (&Shash_table_count); 5952 defsubr (&Shash_table_count);