diff options
author | John Hawthorn <[email protected]> | 2021-08-16 12:51:11 -0700 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-08-18 18:24:37 +0900 |
commit | d668cd188ca91cf08ea7678bad1dd0bc8a997a81 (patch) | |
tree | 0e65e95413d4a306d043ea14d26e31d055267430 /numeric.c | |
parent | 95e7aed82bb2b6ce5268a78d38d51cb6db7f044d (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4747
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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; } |