* range.c (recursive_hash): extracted from range_hash. reject

recursive key.
  (range_hash): use recursive_hash.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-07-17 09:28:46 +00:00
Родитель 2cdcc564fd
Коммит bc2df41365
2 изменённых файлов: 27 добавлений и 12 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Fri Jul 17 18:18:23 2009 Tanaka Akira <akr@fsij.org>
* range.c (recursive_hash): extracted from range_hash. reject
recursive key.
(range_hash): use recursive_hash.
Fri Jul 17 18:11:32 2009 Tanaka Akira <akr@fsij.org>
* struct.c (recursive_hash): extracted from rb_struct_hash. reject

33
range.c
Просмотреть файл

@ -201,6 +201,26 @@ range_eql(VALUE range, VALUE obj)
return Qtrue;
}
static VALUE
recursive_hash(VALUE range, VALUE dummy, int recur)
{
unsigned long hash = EXCL(range);
VALUE v;
if (recur) {
rb_raise(rb_eArgError, "recursive key for hash");
}
hash = rb_hash_start(hash);
v = rb_hash(RANGE_BEG(range));
hash = rb_hash_uint(hash, NUM2LONG(v));
v = rb_hash(RANGE_END(range));
hash = rb_hash_uint(hash, NUM2LONG(v));
hash = rb_hash_uint(hash, EXCL(range) << 24);
hash = rb_hash_end(hash);
return LONG2FIX(hash);
}
/*
* call-seq:
* rng.hash => fixnum
@ -213,18 +233,7 @@ range_eql(VALUE range, VALUE obj)
static VALUE
range_hash(VALUE range)
{
unsigned long hash = EXCL(range);
VALUE v;
hash = rb_hash_start(hash);
v = rb_hash(RANGE_BEG(range));
hash = rb_hash_uint(hash, NUM2LONG(v));
v = rb_hash(RANGE_END(range));
hash = rb_hash_uint(hash, NUM2LONG(v));
hash = rb_hash_uint(hash, EXCL(range) << 24);
hash = rb_hash_end(hash);
return LONG2FIX(hash);
return rb_exec_recursive(recursive_hash, range, 0);
}
static void