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

ruby-changes:62101

From: Nobuyoshi <ko1@a...>
Date: Wed, 1 Jul 2020 22:44:44 +0900 (JST)
Subject: [ruby-changes:62101] 53d2bfd540 (master): Added a few integer case short-circuits

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

From 53d2bfd540c1c9b1038c0b1150b2f397e54b0322 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 30 May 2020 18:15:31 +0900
Subject: Added a few integer case short-circuits


diff --git a/rational.c b/rational.c
index cdd2bad..1a95afd 100644
--- a/rational.c
+++ b/rational.c
@@ -60,6 +60,8 @@ f_add(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/rational.c#L60
 	return x;
     if (FIXNUM_ZERO_P(x))
 	return y;
+    if (RB_INTEGER_TYPE_P(x))
+        return rb_int_plus(x, y);
     return rb_funcall(x, '+', 1, y);
 }
 
@@ -78,6 +80,10 @@ f_lt_p(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/rational.c#L80
 {
     if (FIXNUM_P(x) && FIXNUM_P(y))
 	return (SIGNED_VALUE)x < (SIGNED_VALUE)y;
+    if (RB_INTEGER_TYPE_P(x)) {
+        VALUE r = rb_int_cmp(x, y);
+        if (!NIL_P(r)) return rb_int_negative_p(r);
+    }
     return RTEST(rb_funcall(x, '<', 1, y));
 }
 
@@ -137,11 +143,13 @@ f_to_i(VALUE x) https://github.com/ruby/ruby/blob/trunk/rational.c#L143
     return rb_funcall(x, id_to_i, 0);
 }
 
-inline static VALUE
+inline static int
 f_eqeq_p(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x) && FIXNUM_P(y))
 	return x == y;
+    if (RB_INTEGER_TYPE_P(x))
+        return RTEST(rb_int_equal(x, y));
     return (int)rb_equal(x, y);
 }
 
-- 
cgit v0.10.2


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

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