diff options
author | John Hawthorn <john@hawthorn.email> | 2022-12-16 17:00:13 -0800 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2022-12-17 14:51:49 -0800 |
commit | ea3d3c455294b2ad94c93cbe0e61921d71f1d9d3 (patch) | |
tree | c1ca84b54152ce5bed8dcea66bf2d195b10e1702 /hash.c | |
parent | fbaa5db44a3b0622e2755fd00e0519a603aa9bcb (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6945
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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); } |