mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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`](82e2443d8b/hash.c (L1564)
) as well as [`rb_hash_bulk_insert`](82e2443d8b/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.
This commit is contained in:
parent
dfe944bfbe
commit
57bf354c9a
Notes:
git
2021-10-18 17:41:57 +09:00
1 changed files with 4 additions and 2 deletions
|
@ -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)) */
|
||||
|
|
Loading…
Add table
Reference in a new issue