From bc1e4240ab9c1f4b77b7efc97ebe5cfef3880a3d Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 3 Mar 2008 07:14:27 +0000 Subject: * hash.c (rb_any_hash): shrinks all results in Fixnum range. [ruby-core:15713] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 578e4cd39..eca3e5c6a 100644 --- a/hash.c +++ b/hash.c @@ -75,15 +75,16 @@ static int rb_any_hash(VALUE a) { VALUE hval; + int hnum; switch (TYPE(a)) { case T_FIXNUM: case T_SYMBOL: - return (int)a; + hnum = (int)a; break; case T_STRING: - return rb_str_hash(a); + hnum = rb_str_hash(a); break; default: @@ -91,8 +92,10 @@ rb_any_hash(VALUE a) if (!FIXNUM_P(hval)) { hval = rb_funcall(hval, '%', 1, INT2FIX(536870923)); } - return (int)FIX2LONG(hval); + hnum = (int)FIX2LONG(hval); } + hnum <<= 1; + return RSHIFT(hnum, 1); } static const struct st_hash_type objhash = { -- cgit