summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-03 13:18:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-03 13:18:30 +0000
commit6f2efe84fb6169a03ed191606935a40640d6764c (patch)
treec32c3b4d48daeafb526c4e8d37fe0e9870956129 /hash.c
parentc7159e81fc0d70b67358deaa39d21babbc3d89e7 (diff)
hash.c: detect recursion for all
* hash.c (rb_hash): detect recursion for all `hash' methods. each `hash' methods no longer need to use rb_exec_recursive(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/hash.c b/hash.c
index 6b24c61..7d27c54 100644
--- a/hash.c
+++ b/hash.c
@@ -79,14 +79,17 @@ rb_any_cmp(VALUE a, VALUE b)
static VALUE
hash_recursive(VALUE obj, VALUE arg, int recurse)
{
- if (recurse) return INT2FIX(0);
+ if (recurse) {
+ /* TODO: break to call with the object which eql? to obj */
+ return INT2FIX(0);
+ }
return rb_funcallv(obj, id_hash, 0, 0);
}
VALUE
rb_hash(VALUE obj)
{
- VALUE hval = rb_exec_recursive(hash_recursive, obj, 0);
+ VALUE hval = rb_exec_recursive_paired(hash_recursive, obj, obj, 0);
retry:
switch (TYPE(hval)) {
case T_FIXNUM:
@@ -1959,20 +1962,6 @@ hash_i(VALUE key, VALUE val, VALUE arg)
return ST_CONTINUE;
}
-static VALUE
-recursive_hash(VALUE hash, VALUE dummy, int recur)
-{
- st_index_t hval = RHASH_SIZE(hash);
-
- if (!hval) return INT2FIX(0);
- if (recur)
- hval = rb_hash_uint(rb_hash_start(rb_hash(rb_cHash)), hval);
- else
- rb_hash_foreach(hash, hash_i, (VALUE)&hval);
- hval = rb_hash_end(hval);
- return INT2FIX(hval);
-}
-
/*
* call-seq:
* hsh.hash -> fixnum
@@ -1984,7 +1973,12 @@ recursive_hash(VALUE hash, VALUE dummy, int recur)
static VALUE
rb_hash_hash(VALUE hash)
{
- return rb_exec_recursive_paired(recursive_hash, hash, hash, 0);
+ st_index_t hval = RHASH_SIZE(hash);
+
+ if (!hval) return INT2FIX(0);
+ rb_hash_foreach(hash, hash_i, (VALUE)&hval);
+ hval = rb_hash_end(hval);
+ return INT2FIX(hval);
}
static int