summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-16 17:54:16 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-16 17:54:16 -0800
commit595e55ff7fd02106e7e04bd0db3c2737643fedbd (patch)
treece3b47e5252f7ef0c466d7b3297cb00cf9fe57f1
parent1bab133df8cf48d33296b299a25f0616b10bb7b1 (diff)
downloadtxr-595e55ff7fd02106e7e04bd0db3c2737643fedbd.tar.gz
txr-595e55ff7fd02106e7e04bd0db3c2737643fedbd.tar.bz2
txr-595e55ff7fd02106e7e04bd0db3c2737643fedbd.zip
2011-12-16 Kaz Kylheku <kaz@kylheku.com>
* hash.c (equal_hash): Eliminating displacement from character hashes. Simplifying some code. (eql_hash): Handle fixnums, characters and literals specially, rather than hashing all value types the same way. The shift applicable for object pointers causes adjacent integers to clash.
-rw-r--r--ChangeLog8
-rw-r--r--hash.c40
2 files changed, 37 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 9bb2214c..3885dd09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2011-12-16 Kaz Kylheku <kaz@kylheku.com>
+ * hash.c (equal_hash): Eliminating displacement from character
+ hashes. Simplifying some code.
+ (eql_hash): Handle fixnums, characters and literals specially,
+ rather than hashing all value types the same way. The shift
+ applicable for object pointers causes adjacent integers to clash.
+
+2011-12-16 Kaz Kylheku <kaz@kylheku.com>
+
* eval.c (expand_vars): Bugfix: use expand_forms rather than
expand on a list of forms.
diff --git a/hash.c b/hash.c
index db7be842..ebec6968 100644
--- a/hash.c
+++ b/hash.c
@@ -100,17 +100,17 @@ static cnum equal_hash(val obj)
case STR:
return hash_c_str(obj->st.str);
case CHR:
- return c_chr(obj) + NUM_MAX / 2;
+ return c_chr(obj);
case NUM:
- return c_num(obj) & NUM_MAX;
+ return c_num(obj);
case SYM:
case PKG:
case ENV:
switch (sizeof (mem_t *)) {
case 4:
- return (((cnum) obj) & NUM_MAX) >> 4;
+ return ((cnum) obj) >> 4;
case 8: default:
- return (((cnum) obj) & NUM_MAX) >> 5;
+ return ((cnum) obj) >> 5;
}
break;
case FUN:
@@ -142,14 +142,32 @@ static cnum equal_hash(val obj)
static cnum eql_hash(val obj)
{
- if (bignump(obj))
- return mp_hash(mp(obj));
- switch (sizeof (mem_t *)) {
- case 4:
- return (((cnum) obj) & NUM_MAX) >> 4;
- case 8: default:
- return (((cnum) obj) & NUM_MAX) >> 5;
+ switch (tag(obj)) {
+ case TAG_PTR:
+ if (!obj)
+ return NUM_MAX;
+ if (obj->t.type == BGNUM)
+ return mp_hash(mp(obj));
+ switch (sizeof (mem_t *)) {
+ case 4:
+ return ((cnum) obj) >> 4;
+ case 8: default:
+ return ((cnum) obj) >> 5;
+ }
+ case TAG_CHR:
+ return c_chr(obj);
+ case TAG_NUM:
+ return c_num(obj);
+ case TAG_LIT:
+ switch (sizeof (mem_t *)) {
+ case 4:
+ return ((cnum) obj) >> 2;
+ case 8: default:
+ return ((cnum) obj) >> 3;
+ }
}
+ /* notreached */
+ abort();
}
cnum cobj_hash_op(val obj)