summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2022-12-16 17:00:13 -0800
committerJohn Hawthorn <john@hawthorn.email>2022-12-17 14:51:49 -0800
commitea3d3c455294b2ad94c93cbe0e61921d71f1d9d3 (patch)
treec1ca84b54152ce5bed8dcea66bf2d195b10e1702 /hash.c
parentfbaa5db44a3b0622e2755fd00e0519a603aa9bcb (diff)
downloadruby-ea3d3c455294b2ad94c93cbe0e61921d71f1d9d3.tar.gz
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.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c4
1 files changed, 3 insertions, 1 deletions
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);
}