summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-30 04:54:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-30 04:54:01 +0000
commita94b78e41833d0f6b4e9b566dca234dde4628230 (patch)
treea6086c57fe4f3ccf16c3c42a296909d9976fd865 /hash.c
parent15530088b66031228b55715bfafb7957da747e9b (diff)
hash.c: hoisted out dbl_to_index
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/hash.c b/hash.c
index 22064cf0f3..c8bf4481dd 100644
--- a/hash.c
+++ b/hash.c
@@ -147,6 +147,14 @@ rb_hash(VALUE obj)
long rb_objid_hash(st_index_t index);
+static st_index_t
+dbl_to_index(double d)
+{
+ union {double d; st_index_t i;} u;
+ u.d = d;
+ return u.i;
+}
+
long
rb_dbl_long_hash(double d)
{
@@ -155,12 +163,7 @@ rb_dbl_long_hash(double d)
#if SIZEOF_INT == SIZEOF_VOIDP
return rb_memhash(&d, sizeof(d));
#else
- {
- union {double d; uint64_t i;} u;
-
- u.d = d;
- return rb_objid_hash(u.i);
- }
+ return rb_objid_hash(dbl_to_index(d));
#endif
}
@@ -293,9 +296,7 @@ rb_ident_hash(st_data_t n)
* many integers get interpreted as 2.0 or -2.0 [Bug #10761]
*/
if (FLONUM_P(n)) {
- union { double d; st_data_t i; } u;
- u.d = rb_float_value(n);
- n ^= u.i;
+ n ^= dbl_to_index(rb_float_value(n));
}
#endif