mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Small optimization for the opt_and instruction
This change eagerly performs a bitwise and on the parameters. If both parameters are fixnums, then the result value should also be a fixnum. We can just test the bit on the result and return if it's a fixnum. Otherwise return Qundef.
This commit is contained in:
parent
702f40628a
commit
67faea9708
Notes:
git
2022-03-11 01:44:51 +09:00
1 changed files with 8 additions and 2 deletions
|
@ -5335,9 +5335,15 @@ vm_opt_ltlt(VALUE recv, VALUE obj)
|
|||
static VALUE
|
||||
vm_opt_and(VALUE recv, VALUE obj)
|
||||
{
|
||||
if (FIXNUM_2_P(recv, obj) &&
|
||||
// If recv and obj are both fixnums, then the bottom tag bit
|
||||
// will be 1 on both. 1 & 1 == 1, so the result value will also
|
||||
// be a fixnum. If either side is *not* a fixnum, then the tag bit
|
||||
// will be 0, and we return Qundef.
|
||||
VALUE ret = ((SIGNED_VALUE) recv) & ((SIGNED_VALUE) obj);
|
||||
|
||||
if (FIXNUM_P(ret) &&
|
||||
BASIC_OP_UNREDEFINED_P(BOP_AND, INTEGER_REDEFINED_OP_FLAG)) {
|
||||
return (recv & obj) | 1;
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return Qundef;
|
||||
|
|
Loading…
Add table
Reference in a new issue