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

ruby-changes:65859

From: Nobuyoshi <ko1@a...>
Date: Tue, 13 Apr 2021 16:28:20 +0900 (JST)
Subject: [ruby-changes:65859] 393923b50d (master): Inline LONG_LONG conversions

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

From 393923b50d472468c078c08a4b6f90e7186deb4a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 13 Apr 2021 14:49:49 +0900
Subject: Inline LONG_LONG conversions

Not only NUM2LL, also LL2NUM, ULL2NUM and NUM2ULL.
---
 include/ruby/internal/arithmetic/long_long.h | 29 +++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/include/ruby/internal/arithmetic/long_long.h b/include/ruby/internal/arithmetic/long_long.h
index 96ffb37..a4a5d0a 100644
--- a/include/ruby/internal/arithmetic/long_long.h
+++ b/include/ruby/internal/arithmetic/long_long.h
@@ -25,12 +25,12 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long_long.h#L25
 #include "ruby/internal/special_consts.h"
 #include "ruby/backward/2/long_long.h"
 
-#define RB_LL2NUM  rb_ll2inum
-#define RB_ULL2NUM rb_ull2inum
+#define RB_LL2NUM  rb_ll2num_inline
+#define RB_ULL2NUM rb_ull2num_inline
 #define LL2NUM     RB_LL2NUM
 #define ULL2NUM    RB_ULL2NUM
 #define RB_NUM2LL  rb_num2ll_inline
-#define RB_NUM2ULL rb_num2ull
+#define RB_NUM2ULL rb_num2ull_inline
 #define NUM2LL     RB_NUM2LL
 #define NUM2ULL    RB_NUM2ULL
 
@@ -41,6 +41,20 @@ LONG_LONG rb_num2ll(VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long_long.h#L41
 unsigned LONG_LONG rb_num2ull(VALUE);
 RBIMPL_SYMBOL_EXPORT_END()
 
+static inline VALUE
+rb_ll2num_inline(LONG_LONG n)
+{
+    if (FIXABLE(n)) return LONG2FIX((long)n);
+    return rb_ll2inum(n);
+}
+
+static inline VALUE
+rb_ull2num_inline(unsigned LONG_LONG n)
+{
+    if (POSFIXABLE(n)) return LONG2FIX((long)n);
+    return rb_ull2inum(n);
+}
+
 static inline LONG_LONG
 rb_num2ll_inline(VALUE x)
 {
@@ -50,4 +64,13 @@ rb_num2ll_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long_long.h#L64
         return rb_num2ll(x);
 }
 
+static inline unsigned LONG_LONG
+rb_num2ull_inline(VALUE x)
+{
+    if (RB_FIXNUM_P(x))
+        return RB_FIX2LONG(x);
+    else
+        return rb_num2ull(x);
+}
+
 #endif /* RBIMPL_ARITHMETIC_LONG_LONG_H */
-- 
cgit v1.1


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

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