Hoisted out call_default_proc
This commit is contained in:
parent
b8fa18079d
commit
5b06dd3a42
18
hash.c
18
hash.c
@ -1942,17 +1942,21 @@ rb_hash_rehash(VALUE hash)
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
call_default_proc(VALUE proc, VALUE hash, VALUE key)
|
||||||
|
{
|
||||||
|
VALUE args[2] = {hash, key};
|
||||||
|
return rb_proc_call_with_block(proc, 2, args, Qnil);
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_hash_default_value(VALUE hash, VALUE key)
|
rb_hash_default_value(VALUE hash, VALUE key)
|
||||||
{
|
{
|
||||||
VALUE args[2];
|
|
||||||
if (LIKELY(rb_method_basic_definition_p(CLASS_OF(hash), id_default))) {
|
if (LIKELY(rb_method_basic_definition_p(CLASS_OF(hash), id_default))) {
|
||||||
VALUE ifnone = RHASH_IFNONE(hash);
|
VALUE ifnone = RHASH_IFNONE(hash);
|
||||||
if (!FL_TEST(hash, RHASH_PROC_DEFAULT)) return ifnone;
|
if (!FL_TEST(hash, RHASH_PROC_DEFAULT)) return ifnone;
|
||||||
if (key == Qundef) return Qnil;
|
if (key == Qundef) return Qnil;
|
||||||
args[0] = hash;
|
return call_default_proc(ifnone, hash, key);
|
||||||
args[1] = key;
|
|
||||||
return rb_proc_call_with_block(ifnone, 2, args, Qnil);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_funcall(hash, id_default, 1, key);
|
return rb_funcall(hash, id_default, 1, key);
|
||||||
@ -2119,15 +2123,13 @@ rb_hash_fetch(VALUE hash, VALUE key)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_hash_default(int argc, VALUE *argv, VALUE hash)
|
rb_hash_default(int argc, VALUE *argv, VALUE hash)
|
||||||
{
|
{
|
||||||
VALUE args[2], ifnone;
|
VALUE ifnone;
|
||||||
|
|
||||||
rb_check_arity(argc, 0, 1);
|
rb_check_arity(argc, 0, 1);
|
||||||
ifnone = RHASH_IFNONE(hash);
|
ifnone = RHASH_IFNONE(hash);
|
||||||
if (FL_TEST(hash, RHASH_PROC_DEFAULT)) {
|
if (FL_TEST(hash, RHASH_PROC_DEFAULT)) {
|
||||||
if (argc == 0) return Qnil;
|
if (argc == 0) return Qnil;
|
||||||
args[0] = hash;
|
return call_default_proc(ifnone, hash, argv[0]);
|
||||||
args[1] = argv[0];
|
|
||||||
return rb_proc_call_with_block(ifnone, 2, args, Qnil);
|
|
||||||
}
|
}
|
||||||
return ifnone;
|
return ifnone;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user