Skip to content

Commit bf6099b

Browse files
committed
Use FL_TEST_RAW in rb_hash_default_value
We should always have a T_HASH here, so we can use FL_TEST_RAW to avoid checking whether we may have an immediate value. I expect this to be a very small performance improvement (perf stat ./miniruby benchmark/hash_aref_miss.rb shows a ~1% improvement). It also removes 9 instructions from rb_hash_default_value on x86_64.
1 parent a81807f commit bf6099b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

hash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2088,9 +2088,11 @@ rb_hash_default_unredefined(VALUE hash)
20882088
VALUE
20892089
rb_hash_default_value(VALUE hash, VALUE key)
20902090
{
2091+
RUBY_ASSERT(RB_TYPE_P(hash, T_HASH));
2092+
20912093
if (LIKELY(rb_hash_default_unredefined(hash))) {
20922094
VALUE ifnone = RHASH_IFNONE(hash);
2093-
if (!FL_TEST(hash, RHASH_PROC_DEFAULT)) return ifnone;
2095+
if (LIKELY(!FL_TEST_RAW(hash, RHASH_PROC_DEFAULT))) return ifnone;
20942096
if (UNDEF_P(key)) return Qnil;
20952097
return call_default_proc(ifnone, hash, key);
20962098
}

0 commit comments

Comments
 (0)