From: "jhawthorn (John Hawthorn)" Date: 2021-08-16T20:31:00+00:00 Subject: [ruby-core:104932] [Ruby master Bug#18078] rb_fix2uint should avoid method lookup and use FIXNUM_NEGATIVE_P Issue #18078 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #18078: rb_fix2uint should avoid method lookup and use FIXNUM_NEGATIVE_P https://bugs.ruby-lang.org/issues/18078 * Author: jhawthorn (John Hawthorn) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.0dev * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- `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-------------------------------- 0001-rb_fix2uint-should-use-FIXNUM_NEGATIVE_P.patch (1.27 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: