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
This commit is contained in:
nobu 2013-12-03 13:18:30 +00:00
parent c7159e81fc
commit 6f2efe84fb
6 changed files with 54 additions and 81 deletions

33
array.c
View file

@ -3774,27 +3774,6 @@ rb_ary_eql(VALUE ary1, VALUE ary2)
return rb_exec_recursive_paired(recursive_eql, ary1, ary2, ary2);
}
static VALUE
recursive_hash(VALUE ary, VALUE dummy, int recur)
{
long i;
st_index_t h;
VALUE n;
h = rb_hash_start(RARRAY_LEN(ary));
if (recur) {
h = rb_hash_uint(h, NUM2LONG(rb_hash(rb_cArray)));
}
else {
for (i=0; i<RARRAY_LEN(ary); i++) {
n = rb_hash(RARRAY_AREF(ary, i));
h = rb_hash_uint(h, NUM2LONG(n));
}
}
h = rb_hash_end(h);
return LONG2FIX(h);
}
/*
* call-seq:
* ary.hash -> fixnum
@ -3808,7 +3787,17 @@ recursive_hash(VALUE ary, VALUE dummy, int recur)
static VALUE
rb_ary_hash(VALUE ary)
{
return rb_exec_recursive_paired(recursive_hash, ary, ary, 0);
long i;
st_index_t h;
VALUE n;
h = rb_hash_start(RARRAY_LEN(ary));
for (i=0; i<RARRAY_LEN(ary); i++) {
n = rb_hash(RARRAY_AREF(ary, i));
h = rb_hash_uint(h, NUM2LONG(n));
}
h = rb_hash_end(h);
return LONG2FIX(h);
}
/*