mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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:
parent
c7159e81fc
commit
6f2efe84fb
6 changed files with 54 additions and 81 deletions
36
struct.c
36
struct.c
|
@ -949,27 +949,6 @@ rb_struct_equal(VALUE s, VALUE s2)
|
|||
return rb_exec_recursive_paired(recursive_equal, s, s2, s2);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
recursive_hash(VALUE s, VALUE dummy, int recur)
|
||||
{
|
||||
long i, len;
|
||||
st_index_t h;
|
||||
VALUE n;
|
||||
const VALUE *ptr;
|
||||
|
||||
h = rb_hash_start(rb_hash(rb_obj_class(s)));
|
||||
if (!recur) {
|
||||
ptr = RSTRUCT_CONST_PTR(s);
|
||||
len = RSTRUCT_LEN(s);
|
||||
for (i = 0; i < len; i++) {
|
||||
n = rb_hash(ptr[i]);
|
||||
h = rb_hash_uint(h, NUM2LONG(n));
|
||||
}
|
||||
}
|
||||
h = rb_hash_end(h);
|
||||
return INT2FIX(h);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* struct.hash -> fixnum
|
||||
|
@ -980,7 +959,20 @@ recursive_hash(VALUE s, VALUE dummy, int recur)
|
|||
static VALUE
|
||||
rb_struct_hash(VALUE s)
|
||||
{
|
||||
return rb_exec_recursive_paired(recursive_hash, s, s, 0);
|
||||
long i, len;
|
||||
st_index_t h;
|
||||
VALUE n;
|
||||
const VALUE *ptr;
|
||||
|
||||
h = rb_hash_start(rb_hash(rb_obj_class(s)));
|
||||
ptr = RSTRUCT_CONST_PTR(s);
|
||||
len = RSTRUCT_LEN(s);
|
||||
for (i = 0; i < len; i++) {
|
||||
n = rb_hash(ptr[i]);
|
||||
h = rb_hash_uint(h, NUM2LONG(n));
|
||||
}
|
||||
h = rb_hash_end(h);
|
||||
return INT2FIX(h);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue