From ea3d3c455294b2ad94c93cbe0e61921d71f1d9d3 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 16 Dec 2022 17:00:13 -0800 Subject: 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. --- hash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hash.c b/hash.c index 1923c63eb3..5204d8b018 100644 --- a/hash.c +++ b/hash.c @@ -2088,9 +2088,11 @@ rb_hash_default_unredefined(VALUE hash) VALUE rb_hash_default_value(VALUE hash, VALUE key) { + RUBY_ASSERT(RB_TYPE_P(hash, T_HASH)); + if (LIKELY(rb_hash_default_unredefined(hash))) { VALUE ifnone = RHASH_IFNONE(hash); - if (!FL_TEST(hash, RHASH_PROC_DEFAULT)) return ifnone; + if (LIKELY(!FL_TEST_RAW(hash, RHASH_PROC_DEFAULT))) return ifnone; if (UNDEF_P(key)) return Qnil; return call_default_proc(ifnone, hash, key); } -- cgit v1.2.3