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

ruby-changes:16830

From: mrkn <ko1@a...>
Date: Sun, 1 Aug 2010 22:20:40 +0900 (JST)
Subject: [ruby-changes:16830] Ruby:r28825 (trunk): * ext/bigdecimal/bigdecimal.c (BigDecimal_hash): use rb_memhash and take care of negative finite numbers properly.

mrkn	2010-08-01 22:20:22 +0900 (Sun, 01 Aug 2010)

  New Revision: 28825

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28825

  Log:
    * ext/bigdecimal/bigdecimal.c (BigDecimal_hash): use rb_memhash and take care of negative finite numbers properly.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28824)
+++ ChangeLog	(revision 28825)
@@ -1,3 +1,8 @@
+Sun Aug  1 22:16:30 2010  Kenta Murata  <mrkn@m...>
+
+	* ext/bigdecimal/bigdecimal.c (BigDecimal_hash): use rb_memhash and
+	  take care of negative finite numbers properly.
+
 Sun Aug  1 20:57:22 2010  Tanaka Akira  <akr@f...>
 
 	* ext/pathname/pathname.c (path_realpath): Pathname#realpath translated
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 28824)
+++ ext/bigdecimal/bigdecimal.c	(revision 28825)
@@ -228,12 +228,9 @@
     GUARD_OBJ(p,GetVpValue(self,1));
     hash = (U_LONG)p->sign;
     /* hash!=2: the case for 0(1),NaN(0) or +-Infinity(3) is sign itself */
-    if(hash==2) {
-        for(i = 0; i < p->Prec;i++) {
-            hash = 31 * hash + p->frac[i];
-            hash ^= p->frac[i];
-        }
-        hash += p->exponent;
+    if(hash == 2 || hash == -2) {
+	hash ^= rb_memhash(p->frac, sizeof(U_LONG)*p->Prec);
+	hash += p->exponent;
     }
     return INT2FIX(hash);
 }

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

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