summaryrefslogtreecommitdiffstats
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
commita9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951 (patch)
tree4c526eff2fde246ab1b6c4373e0b44c417dd860c
parentafba8c78ff2ee42dc9f8951ef3c4c89ba8a13076 (diff)
downloadtxr-a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951.tar.gz
txr-a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951.tar.bz2
txr-a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951.zip
hash: replace hashing function for doubles.
* hash.c (hash_double): Rewrite silly byte rotation with union aliased against ucnum array.
-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;
}