1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

rb_fix2uint should use FIXNUM_NEGATIVE_P

rb_num_negative_int_p is equivalent to calling the "<" method on
Integer (and checking whether it is overridden), where in this case we
are interested in whether the "actual" value can fit inside an unsigned
int.

This also was slow because rb_num_negative_int_p calls
rb_method_basic_definition_p, doing a method lookup to check for < being
overridden.

This replaces the check in both rb_fix2uint and rb_fix2ushort with FIXNUM_NEGATIVE_P which simply checks
whether the VALUE is signed.
This commit is contained in:
John Hawthorn 2021-08-16 12:51:11 -07:00 committed by Nobuyoshi Nakada
parent 95e7aed82b
commit d668cd188c
Notes: git 2021-08-18 18:24:58 +09:00

View file

@ -2924,7 +2924,7 @@ rb_fix2uint(VALUE val)
}
num = FIX2ULONG(val);
check_uint(num, rb_num_negative_int_p(val));
check_uint(num, FIXNUM_NEGATIVE_P(val));
return num;
}
#else
@ -3022,7 +3022,7 @@ rb_fix2ushort(VALUE val)
}
num = FIX2ULONG(val);
check_ushort(num, rb_num_negative_int_p(val));
check_ushort(num, FIXNUM_NEGATIVE_P(val));
return num;
}