summaryrefslogtreecommitdiff
path: root/insns.def
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-10-16 11:20:30 -0700
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-18 17:41:38 +0900
commit57bf354c9a878bb67c294408400fd029f9b5a353 (patch)
tree036dca8fcd9066eee1e040d4b58ef9c570fde8bd /insns.def
parentdfe944bfbed3cae47e3874de4ed0d2a96c047738 (diff)
Eliminate some redundant checks on `num` in `newhash`
The `newhash` instruction was checking if `num` is greater than 0, but so is [`rb_hash_new_with_size`](https://github.com/ruby/ruby/blob/82e2443d8b1e3edd2607c78dddf5aac79a13492d/hash.c#L1564) as well as [`rb_hash_bulk_insert`](https://github.com/ruby/ruby/blob/82e2443d8b1e3edd2607c78dddf5aac79a13492d/hash.c#L4764). If we know the size is 0 in the instruction, we can just directly call `rb_hash_new` and only check the size once. Unfortunately, when num is greater than 0, it's still checked 3 times.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4977
Diffstat (limited to 'insns.def')
-rw-r--r--insns.def6
1 files changed, 4 insertions, 2 deletions
diff --git a/insns.def b/insns.def
index 43690be52e..7dfeed202b 100644
--- a/insns.def
+++ b/insns.def
@@ -526,11 +526,13 @@ newhash
{
RUBY_DTRACE_CREATE_HOOK(HASH, num);
- val = rb_hash_new_with_size(num / 2);
-
if (num) {
+ val = rb_hash_new_with_size(num / 2);
rb_hash_bulk_insert(num, STACK_ADDR_FROM_TOP(num), val);
}
+ else {
+ val = rb_hash_new();
+ }
}
/* put new Range object.(Range.new(low, high, flag)) */