From 987df2ece681f522d9286f0fef410bb373988bd6 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 29 Jul 2015 08:25:49 +0000 Subject: hash.c: move rb_obj_hash * hash.c (rb_obj_hash): move in order to share with rb_any_hash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index e852570183..07d88a7d66 100644 --- a/hash.c +++ b/hash.c @@ -129,23 +129,8 @@ rb_hash(VALUE obj) long rb_objid_hash(st_index_t index); -VALUE -rb_sym_hash(VALUE sym) -{ - st_index_t hnum; - - if (STATIC_SYM_P(sym)) { - sym >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT); - hnum = rb_objid_hash((st_index_t)sym); - } - else { - hnum = RSYMBOL(sym)->hashval; - } - return LONG2FIX(hnum); -} - static st_index_t -rb_any_hash(VALUE a) +any_hash(VALUE a, st_index_t (*other_func)(VALUE)) { VALUE hval; st_index_t hnum; @@ -173,13 +158,25 @@ rb_any_hash(VALUE a) hnum = FIX2LONG(hval); } else { - hval = rb_hash(a); - hnum = FIX2LONG(hval); + hnum = other_func(a); } hnum <<= 1; return (st_index_t)RSHIFT(hnum, 1); } +static st_index_t +obj_any_hash(VALUE obj) +{ + obj = rb_hash(obj); + return FIX2LONG(obj); +} + +static st_index_t +rb_any_hash(VALUE a) +{ + return any_hash(a, obj_any_hash); +} + long rb_objid_hash(st_index_t index) { @@ -189,6 +186,19 @@ rb_objid_hash(st_index_t index) return hnum; } +static st_index_t +objid_hash(VALUE obj) +{ + return rb_objid_hash((st_index_t)obj); +} + +VALUE +rb_obj_hash(VALUE obj) +{ + st_index_t hnum = any_hash(obj, objid_hash); + return LONG2FIX(hnum); +} + int rb_hash_iter_lev(VALUE h) { -- cgit v1.2.3