Bug #18078
closedrb_fix2uint should avoid method lookup and use FIXNUM_NEGATIVE_P
Description
rb_fix2uint checks if the FIXNUM being converted overflows the unsigned int type. Previously this check was being done with rb_num_negative_int_p, which 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 made rb_fix2uint potentially behave differently than rb_num2uint, which checked the "actual" sign.
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.
Included is a patch to replace the check in both rb_fix2uint and rb_fix2ushort with FIXNUM_NEGATIVE_P, which simply checks
whether the VALUE is signed. (also submitted as a PR https://github.com/ruby/ruby/pull/4747)
I filed this as a bug, but I don't think this will affect anyone (backport not necessary, nobody should be overriding Integer#< I don't think) other than as a performance improvement.
Files
Updated by jeremyevans0 (Jeremy Evans) about 4 years ago
- Status changed from Open to Closed