summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2021-08-16 12:51:11 -0700
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-08-18 18:24:37 +0900
commitd668cd188ca91cf08ea7678bad1dd0bc8a997a81 (patch)
tree0e65e95413d4a306d043ea14d26e31d055267430 /numeric.c
parent95e7aed82bb2b6ce5268a78d38d51cb6db7f044d (diff)
downloadruby-d668cd188ca91cf08ea7678bad1dd0bc8a997a81.tar.gz
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.
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c4
1 files 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;
}