summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-29 08:25:49 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-29 08:25:49 (GMT)
commit987df2ece681f522d9286f0fef410bb373988bd6 (patch)
tree5e5b58ad564b018b23cf4631b3a70a2009721891 /hash.c
parent07900180ec9b6f8ce79b69e54ed51f18cabffc60 (diff)
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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/hash.c b/hash.c
index e852570..07d88a7 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)
{