[前][次][番号順一覧][スレッド一覧]

ruby-changes:67184

From: John <ko1@a...>
Date: Wed, 18 Aug 2021 18:24:48 +0900 (JST)
Subject: [ruby-changes:67184] d668cd188c (master): rb_fix2uint should use FIXNUM_NEGATIVE_P

https://git.ruby-lang.org/ruby.git/commit/?id=d668cd188c

From d668cd188ca91cf08ea7678bad1dd0bc8a997a81 Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@h...>
Date: Mon, 16 Aug 2021 12:51:11 -0700
Subject: 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 a1801f9..f04cf61 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2924,7 +2924,7 @@ rb_fix2uint(VALUE val) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2924
     }
     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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3022
     }
     num = FIX2ULONG(val);
 
-    check_ushort(num, rb_num_negative_int_p(val));
+    check_ushort(num, FIXNUM_NEGATIVE_P(val));
     return num;
 }
 
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]