summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-07-17 06:25:19 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-07-17 06:25:19 -0700
commitd879eb7226e928e41c45c1702ed3685e0b8e1757 (patch)
tree4c526eff2fde246ab1b6c4373e0b44c417dd860c /hash.c
parent5d4d3a6a0c26e5112e0ecd7b5556294ce292555c (diff)
downloadtxr-d879eb7226e928e41c45c1702ed3685e0b8e1757.tar.gz
txr-d879eb7226e928e41c45c1702ed3685e0b8e1757.tar.bz2
txr-d879eb7226e928e41c45c1702ed3685e0b8e1757.zip
hash: replace hashing function for doubles.
* hash.c (hash_double): Rewrite silly byte rotation with union aliased against ucnum array.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index 34247e64..e5f00ecf 100644
--- a/hash.c
+++ b/hash.c
@@ -181,14 +181,17 @@ static u32_t hash_buf(const mem_t *ptr, ucnum size, u32_t seed)
static ucnum hash_double(double n)
{
+ union hack {
+ volatile double d;
+ volatile ucnum a[sizeof (double) / sizeof (ucnum)];
+ } u;
ucnum h = 0;
+ int i;
- mem_t *p = coerce(mem_t *, &n), *q = p + sizeof(double);
+ u.d = n;
- while (p < q) {
- h = h << 8 | h >> (8 * sizeof h - 1);
- h += *p++;
- }
+ for (i = 0; i < sizeof u.a / sizeof u.a[0]; i++)
+ h += u.a[i];
return h;
}