From 19a903d87f6a876da709f1a9291c01018b9c74f4 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 16 Aug 2021 12:51:11 -0700 Subject: [PATCH] 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. --- numeric.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numeric.c b/numeric.c index a1801f9654..f04cf61b0d 100644 --- a/numeric.c +++ b/numeric.c @@ -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; } -- 2.32.0