diff options
| -rw-r--r-- | src/fns.c | 68 | ||||
| -rw-r--r-- | src/lisp.h | 8 |
2 files changed, 28 insertions, 48 deletions
| @@ -3667,8 +3667,6 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max) | |||
| 3667 | Low-level Functions | 3667 | Low-level Functions |
| 3668 | ***********************************************************************/ | 3668 | ***********************************************************************/ |
| 3669 | 3669 | ||
| 3670 | struct hash_table_test hashtest_eq, hashtest_eql, hashtest_equal; | ||
| 3671 | |||
| 3672 | /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code | 3670 | /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code |
| 3673 | HASH2 in hash table H using `eql'. Value is true if KEY1 and | 3671 | HASH2 in hash table H using `eql'. Value is true if KEY1 and |
| 3674 | KEY2 are the same. */ | 3672 | KEY2 are the same. */ |
| @@ -3709,7 +3707,6 @@ cmpfn_user_defined (struct hash_table_test *ht, | |||
| 3709 | return !NILP (call2 (ht->user_cmp_function, key1, key2)); | 3707 | return !NILP (call2 (ht->user_cmp_function, key1, key2)); |
| 3710 | } | 3708 | } |
| 3711 | 3709 | ||
| 3712 | |||
| 3713 | /* Value is a hash code for KEY for use in hash table H which uses | 3710 | /* Value is a hash code for KEY for use in hash table H which uses |
| 3714 | `eq' to compare keys. The hash code returned is guaranteed to fit | 3711 | `eq' to compare keys. The hash code returned is guaranteed to fit |
| 3715 | in a Lisp integer. */ | 3712 | in a Lisp integer. */ |
| @@ -3717,34 +3714,27 @@ cmpfn_user_defined (struct hash_table_test *ht, | |||
| 3717 | static EMACS_UINT | 3714 | static EMACS_UINT |
| 3718 | hashfn_eq (struct hash_table_test *ht, Lisp_Object key) | 3715 | hashfn_eq (struct hash_table_test *ht, Lisp_Object key) |
| 3719 | { | 3716 | { |
| 3720 | EMACS_UINT hash = XHASH (key) ^ XTYPE (key); | 3717 | return XHASH (key) ^ XTYPE (key); |
| 3721 | return hash; | ||
| 3722 | } | 3718 | } |
| 3723 | 3719 | ||
| 3724 | /* Value is a hash code for KEY for use in hash table H which uses | 3720 | /* Value is a hash code for KEY for use in hash table H which uses |
| 3725 | `eql' to compare keys. The hash code returned is guaranteed to fit | 3721 | `equal' to compare keys. The hash code returned is guaranteed to fit |
| 3726 | in a Lisp integer. */ | 3722 | in a Lisp integer. */ |
| 3727 | 3723 | ||
| 3728 | static EMACS_UINT | 3724 | static EMACS_UINT |
| 3729 | hashfn_eql (struct hash_table_test *ht, Lisp_Object key) | 3725 | hashfn_equal (struct hash_table_test *ht, Lisp_Object key) |
| 3730 | { | 3726 | { |
| 3731 | EMACS_UINT hash; | 3727 | return sxhash (key, 0); |
| 3732 | if (FLOATP (key)) | ||
| 3733 | hash = sxhash (key, 0); | ||
| 3734 | else | ||
| 3735 | hash = XHASH (key) ^ XTYPE (key); | ||
| 3736 | return hash; | ||
| 3737 | } | 3728 | } |
| 3738 | 3729 | ||
| 3739 | /* Value is a hash code for KEY for use in hash table H which uses | 3730 | /* Value is a hash code for KEY for use in hash table H which uses |
| 3740 | `equal' to compare keys. The hash code returned is guaranteed to fit | 3731 | `eql' to compare keys. The hash code returned is guaranteed to fit |
| 3741 | in a Lisp integer. */ | 3732 | in a Lisp integer. */ |
| 3742 | 3733 | ||
| 3743 | static EMACS_UINT | 3734 | static EMACS_UINT |
| 3744 | hashfn_equal (struct hash_table_test *ht, Lisp_Object key) | 3735 | hashfn_eql (struct hash_table_test *ht, Lisp_Object key) |
| 3745 | { | 3736 | { |
| 3746 | EMACS_UINT hash = sxhash (key, 0); | 3737 | return FLOATP (key) ? hashfn_equal (ht, key) : hashfn_eq (ht, key); |
| 3747 | return hash; | ||
| 3748 | } | 3738 | } |
| 3749 | 3739 | ||
| 3750 | /* Value is a hash code for KEY for use in hash table H which uses as | 3740 | /* Value is a hash code for KEY for use in hash table H which uses as |
| @@ -3758,6 +3748,14 @@ hashfn_user_defined (struct hash_table_test *ht, Lisp_Object key) | |||
| 3758 | return hashfn_eq (ht, hash); | 3748 | return hashfn_eq (ht, hash); |
| 3759 | } | 3749 | } |
| 3760 | 3750 | ||
| 3751 | struct hash_table_test const | ||
| 3752 | hashtest_eq = { LISPSYM_INITIALLY (Qeq), LISPSYM_INITIALLY (Qnil), | ||
| 3753 | LISPSYM_INITIALLY (Qnil), 0, hashfn_eq }, | ||
| 3754 | hashtest_eql = { LISPSYM_INITIALLY (Qeql), LISPSYM_INITIALLY (Qnil), | ||
| 3755 | LISPSYM_INITIALLY (Qnil), cmpfn_eql, hashfn_eql }, | ||
| 3756 | hashtest_equal = { LISPSYM_INITIALLY (Qequal), LISPSYM_INITIALLY (Qnil), | ||
| 3757 | LISPSYM_INITIALLY (Qnil), cmpfn_equal, hashfn_equal }; | ||
| 3758 | |||
| 3761 | /* Allocate basically initialized hash table. */ | 3759 | /* Allocate basically initialized hash table. */ |
| 3762 | 3760 | ||
| 3763 | static struct Lisp_Hash_Table * | 3761 | static struct Lisp_Hash_Table * |
| @@ -4448,33 +4446,29 @@ sxhash (Lisp_Object obj, int depth) | |||
| 4448 | ***********************************************************************/ | 4446 | ***********************************************************************/ |
| 4449 | 4447 | ||
| 4450 | DEFUN ("sxhash-eq", Fsxhash_eq, Ssxhash_eq, 1, 1, 0, | 4448 | DEFUN ("sxhash-eq", Fsxhash_eq, Ssxhash_eq, 1, 1, 0, |
| 4451 | doc: /* Compute identity hash code for OBJ and return it as integer. | 4449 | doc: /* Return an integer hash code for OBJ suitable for `eq'. |
| 4452 | In other words, hash codes of two non-`eq' lists will be (most likely) | 4450 | If (eq A B), then (= (sxhash-eq A) (sxhash-eq B)). */) |
| 4453 | different, even if the lists contain the same elements. */) | ||
| 4454 | (Lisp_Object obj) | 4451 | (Lisp_Object obj) |
| 4455 | { | 4452 | { |
| 4456 | return make_number (hashfn_eq (NULL, obj)); | 4453 | return make_number (hashfn_eq (NULL, obj)); |
| 4457 | } | 4454 | } |
| 4458 | 4455 | ||
| 4459 | DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0, | 4456 | DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0, |
| 4460 | doc: /* Compute identity hash code for OBJ and return it as integer. | 4457 | doc: /* Return an integer hash code for OBJ suitable for `eql'. |
| 4461 | In comparison to `sxhash-eq', it is also guaranteed that hash codes | 4458 | If (eql A B), then (= (sxhash-eql A) (sxhash-eql B)). */) |
| 4462 | of equal float numbers will be the same, even if the numbers are not | ||
| 4463 | the same Lisp object. */) | ||
| 4464 | (Lisp_Object obj) | 4459 | (Lisp_Object obj) |
| 4465 | { | 4460 | { |
| 4466 | return make_number (hashfn_eql (NULL, obj)); | 4461 | return make_number (hashfn_eql (NULL, obj)); |
| 4467 | } | 4462 | } |
| 4468 | 4463 | ||
| 4469 | DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0, | 4464 | DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0, |
| 4470 | doc: /* Compute a hash code for OBJ and return it as integer. */) | 4465 | doc: /* Return an integer hash code for OBJ suitable for `equal'. |
| 4466 | If (equal A B), then (= (sxhash-equal A) (sxhash-equal B)). */) | ||
| 4471 | (Lisp_Object obj) | 4467 | (Lisp_Object obj) |
| 4472 | { | 4468 | { |
| 4473 | EMACS_UINT hash = sxhash (obj, 0); | 4469 | return make_number (hashfn_equal (NULL, obj)); |
| 4474 | return make_number (hash); | ||
| 4475 | } | 4470 | } |
| 4476 | 4471 | ||
| 4477 | |||
| 4478 | DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0, | 4472 | DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0, |
| 4479 | doc: /* Create and return a new hash table. | 4473 | doc: /* Create and return a new hash table. |
| 4480 | 4474 | ||
| @@ -5220,22 +5214,4 @@ this variable. */); | |||
| 5220 | defsubr (&Ssecure_hash); | 5214 | defsubr (&Ssecure_hash); |
| 5221 | defsubr (&Sbuffer_hash); | 5215 | defsubr (&Sbuffer_hash); |
| 5222 | defsubr (&Slocale_info); | 5216 | defsubr (&Slocale_info); |
| 5223 | |||
| 5224 | hashtest_eq.name = Qeq; | ||
| 5225 | hashtest_eq.user_hash_function = Qnil; | ||
| 5226 | hashtest_eq.user_cmp_function = Qnil; | ||
| 5227 | hashtest_eq.cmpfn = 0; | ||
| 5228 | hashtest_eq.hashfn = hashfn_eq; | ||
| 5229 | |||
| 5230 | hashtest_eql.name = Qeql; | ||
| 5231 | hashtest_eql.user_hash_function = Qnil; | ||
| 5232 | hashtest_eql.user_cmp_function = Qnil; | ||
| 5233 | hashtest_eql.cmpfn = cmpfn_eql; | ||
| 5234 | hashtest_eql.hashfn = hashfn_eql; | ||
| 5235 | |||
| 5236 | hashtest_equal.name = Qequal; | ||
| 5237 | hashtest_equal.user_hash_function = Qnil; | ||
| 5238 | hashtest_equal.user_cmp_function = Qnil; | ||
| 5239 | hashtest_equal.cmpfn = cmpfn_equal; | ||
| 5240 | hashtest_equal.hashfn = hashfn_equal; | ||
| 5241 | } | 5217 | } |
diff --git a/src/lisp.h b/src/lisp.h index 170da67c61c..d111a78f3e0 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -721,12 +721,16 @@ struct Lisp_Symbol | |||
| 721 | except the former expands to an integer constant expression. */ | 721 | except the former expands to an integer constant expression. */ |
| 722 | #define XLI_BUILTIN_LISPSYM(iname) TAG_SYMOFFSET ((iname) * sizeof *lispsym) | 722 | #define XLI_BUILTIN_LISPSYM(iname) TAG_SYMOFFSET ((iname) * sizeof *lispsym) |
| 723 | 723 | ||
| 724 | /* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is | ||
| 725 | designed for use as an initializer, even for a constant initializer. */ | ||
| 726 | #define LISPSYM_INITIALLY(name) LISP_INITIALLY (XLI_BUILTIN_LISPSYM (i##name)) | ||
| 727 | |||
| 724 | /* Declare extern constants for Lisp symbols. These can be helpful | 728 | /* Declare extern constants for Lisp symbols. These can be helpful |
| 725 | when using a debugger like GDB, on older platforms where the debug | 729 | when using a debugger like GDB, on older platforms where the debug |
| 726 | format does not represent C macros. */ | 730 | format does not represent C macros. */ |
| 727 | #define DEFINE_LISP_SYMBOL(name) \ | 731 | #define DEFINE_LISP_SYMBOL(name) \ |
| 728 | DEFINE_GDB_SYMBOL_BEGIN (Lisp_Object, name) \ | 732 | DEFINE_GDB_SYMBOL_BEGIN (Lisp_Object, name) \ |
| 729 | DEFINE_GDB_SYMBOL_END (LISP_INITIALLY (XLI_BUILTIN_LISPSYM (i##name))) | 733 | DEFINE_GDB_SYMBOL_END (LISPSYM_INITIALLY (name)) |
| 730 | 734 | ||
| 731 | /* By default, define macros for Qt, etc., as this leads to a bit | 735 | /* By default, define macros for Qt, etc., as this leads to a bit |
| 732 | better performance in the core Emacs interpreter. A plugin can | 736 | better performance in the core Emacs interpreter. A plugin can |
| @@ -3441,7 +3445,7 @@ ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *); | |||
| 3441 | ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, | 3445 | ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, |
| 3442 | EMACS_UINT); | 3446 | EMACS_UINT); |
| 3443 | void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object); | 3447 | void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object); |
| 3444 | extern struct hash_table_test hashtest_eq, hashtest_eql, hashtest_equal; | 3448 | extern struct hash_table_test const hashtest_eq, hashtest_eql, hashtest_equal; |
| 3445 | extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object, | 3449 | extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object, |
| 3446 | ptrdiff_t, ptrdiff_t *, ptrdiff_t *); | 3450 | ptrdiff_t, ptrdiff_t *, ptrdiff_t *); |
| 3447 | extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, | 3451 | extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, |