[前][次][番号順一覧][スレッド一覧]

ruby-changes:54728

From: nobu <ko1@a...>
Date: Wed, 30 Jan 2019 13:54:06 +0900 (JST)
Subject: [ruby-changes:54728] nobu:r66945 (trunk): hash.c: hoisted out dbl_to_index

nobu	2019-01-30 13:54:01 +0900 (Wed, 30 Jan 2019)

  New Revision: 66945

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66945

  Log:
    hash.c: hoisted out dbl_to_index

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 66944)
+++ hash.c	(revision 66945)
@@ -147,6 +147,14 @@ rb_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/hash.c#L147
 
 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) https://github.com/ruby/ruby/blob/trunk/hash.c#L163
 #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) https://github.com/ruby/ruby/blob/trunk/hash.c#L296
      *   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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]