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

ruby-changes:67990

From: S.H <ko1@a...>
Date: Wed, 15 Sep 2021 08:11:21 +0900 (JST)
Subject: [ruby-changes:67990] b8c3a84bdd (master): Refactor and Using RBOOL macro

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

From b8c3a84bddac7366c4e391234b2535253869e885 Mon Sep 17 00:00:00 2001
From: "S.H" <gamelinks007@g...>
Date: Wed, 15 Sep 2021 08:11:05 +0900
Subject: Refactor and Using RBOOL macro

---
 bignum.c   | 19 +++++--------------
 compar.c   |  3 +--
 complex.c  |  5 +----
 error.c    |  9 ++-------
 file.c     | 15 +++++----------
 numeric.c  | 39 +++++++++++++--------------------------
 re.c       |  8 ++------
 string.c   |  3 +--
 thread.c   | 15 ++-------------
 variable.c |  8 ++------
 10 files changed, 34 insertions(+), 90 deletions(-)

diff --git a/bignum.c b/bignum.c
index 52f62b8..7adf55d 100644
--- a/bignum.c
+++ b/bignum.c
@@ -5387,18 +5387,14 @@ rb_integer_float_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5387
     if (FIXNUM_P(x)) {
 #if SIZEOF_LONG * CHAR_BIT < DBL_MANT_DIG /* assume FLT_RADIX == 2 */
         double xd = (double)FIX2LONG(x);
-        if (xd != yd)
-            return Qfalse;
-        return Qtrue;
+        return RBOOL(xd == yd);
 #else
         long xn, yn;
         if (yi < LONG_MIN || LONG_MAX_as_double <= yi)
             return Qfalse;
         xn = FIX2LONG(x);
         yn = (long)yi;
-        if (xn != yn)
-            return Qfalse;
-        return Qtrue;
+        return RBOOL(xn == yn);
 #endif
     }
     y = rb_dbl2big(yi);
@@ -5527,8 +5523,7 @@ rb_big_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5523
     }
     if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse;
     if (BIGNUM_LEN(x) != BIGNUM_LEN(y)) return Qfalse;
-    if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) != 0) return Qfalse;
-    return Qtrue;
+    return RBOOL(MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) == 0);
 }
 
 VALUE
@@ -5537,8 +5532,7 @@ rb_big_eql(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5532
     if (!RB_BIGNUM_TYPE_P(y)) return Qfalse;
     if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse;
     if (BIGNUM_LEN(x) != BIGNUM_LEN(y)) return Qfalse;
-    if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) != 0) return Qfalse;
-    return Qtrue;
+    return RBOOL(MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) == 0);
 }
 
 VALUE
@@ -6821,10 +6815,7 @@ rb_big_bit_length(VALUE big) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6815
 VALUE
 rb_big_odd_p(VALUE num)
 {
-    if (BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) {
-	return Qtrue;
-    }
-    return Qfalse;
+    return RBOOL(BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1);
 }
 
 VALUE
diff --git a/compar.c b/compar.c
index 7974017..e9d1ac4 100644
--- a/compar.c
+++ b/compar.c
@@ -84,8 +84,7 @@ cmp_equal(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/compar.c#L84
     c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);
 
     if (NIL_P(c)) return Qfalse;
-    if (rb_cmpint(c, x, y) == 0) return Qtrue;
-    return Qfalse;
+    return RBOOL(rb_cmpint(c, x, y) == 0);
 }
 
 static int
diff --git a/complex.c b/complex.c
index ec77aeb..ea3c137 100644
--- a/complex.c
+++ b/complex.c
@@ -1451,10 +1451,7 @@ rb_complex_finite_p(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1451
 {
     get_dat1(self);
 
-    if (f_finite_p(dat->real) && f_finite_p(dat->imag)) {
-	return Qtrue;
-    }
-    return Qfalse;
+    return RBOOL(f_finite_p(dat->real) && f_finite_p(dat->imag));
 }
 
 /*
diff --git a/error.c b/error.c
index b589384..8490220 100644
--- a/error.c
+++ b/error.c
@@ -1548,9 +1548,7 @@ exc_equal(VALUE exc, VALUE obj) https://github.com/ruby/ruby/blob/trunk/error.c#L1548
 
     if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
 	return Qfalse;
-    if (!rb_equal(exc_backtrace(exc), backtrace))
-	return Qfalse;
-    return Qtrue;
+    return rb_equal(exc_backtrace(exc), backtrace);
 }
 
 /*
@@ -1638,10 +1636,7 @@ exit_success_p(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1636
     if (NIL_P(status_val))
 	return Qtrue;
     status = NUM2INT(status_val);
-    if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
-	return Qtrue;
-
-    return Qfalse;
+    return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
 }
 
 static VALUE
diff --git a/file.c b/file.c
index f5d01fd..98b9d50 100644
--- a/file.c
+++ b/file.c
@@ -2019,8 +2019,7 @@ rb_file_file_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L2019
     struct stat st;
 
     if (rb_stat(fname, &st) < 0) return Qfalse;
-    if (S_ISREG(st.st_mode)) return Qtrue;
-    return Qfalse;
+    return RBOOL(S_ISREG(st.st_mode));
 }
 
 /*
@@ -2039,8 +2038,7 @@ rb_file_zero_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L2038
     struct stat st;
 
     if (rb_stat(fname, &st) < 0) return Qfalse;
-    if (st.st_size == 0) return Qtrue;
-    return Qfalse;
+    return RBOOL(st.st_size == 0);
 }
 
 /*
@@ -2080,8 +2078,7 @@ rb_file_owned_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L2078
     struct stat st;
 
     if (rb_stat(fname, &st) < 0) return Qfalse;
-    if (st.st_uid == geteuid()) return Qtrue;
-    return Qfalse;
+    return RBOOL(st.st_uid == geteuid());
 }
 
 static VALUE
@@ -2090,8 +2087,7 @@ rb_file_rowned_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L2087
     struct stat st;
 
     if (rb_stat(fname, &st) < 0) return Qfalse;
-    if (st.st_uid == getuid()) return Qtrue;
-    return Qfalse;
+    return RBOOL(st.st_uid == getuid());
 }
 
 /*
@@ -2124,8 +2120,7 @@ check3rdbyte(VALUE fname, int mode) https://github.com/ruby/ruby/blob/trunk/file.c#L2120
     struct stat st;
 
     if (rb_stat(fname, &st) < 0) return Qfalse;
-    if (st.st_mode & mode) return Qtrue;
-    return Qfalse;
+    return RBOOL(st.st_mode & mode);
 }
 #endif
 
diff --git a/numeric.c b/numeric.c
index 39c2bd7..3b481b3 100644
--- a/numeric.c
+++ b/numeric.c
@@ -755,18 +755,10 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L755
 int_zero_p(VALUE num)
 {
     if (FIXNUM_P(num)) {
-	if (FIXNUM_ZERO_P(num)) {
-	    return Qtrue;
-	}
-    }
-    else {
-        assert(RB_BIGNUM_TYPE_P(num));
-	if (rb_bigzero_p(num)) {
-	    /* this should not happen usually */
-	    return Qtrue;
-	}
+        return RBOOL(FIXNUM_ZERO_P(num));
     }
-    return Qfalse;
+    assert(RB_BIGNUM_TYPE_P(num));
+    return RBOOL(rb_bigzero_p(num));
 }
 
 VALUE
@@ -1368,7 +1360,7 @@ rb_float_equal(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1360
 #if MSC_VERSION_BEFORE(1300)
     if (isnan(a)) return Qfalse;
 #endif
-    return (a == b)?Qtrue:Qfalse;
+    return RBOOL(a == b);
 }
 
 #define flo_eq rb_float_equal
@@ -1491,7 +1483,7 @@ rb_float_gt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1483
 #if MSC_VERSION_BEFORE(1300)
     if (isnan(a)) return Qfalse;
 #endif
-    return (a > b)?Qtrue:Qfalse;
+    return RBOOL(a > b);
 }
 
 /*
@@ -1528,7 +1520,7 @@ flo_ge(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1520
 #if MSC_VERSION_BEFORE(1300)
     if (isnan(a)) return Qfalse;
 #endif
-    return (a >= b)?Qtrue:Qfalse;
+    return RBOOL(a >= b);
 }
 
 /*
@@ -1565,7 +1557,7 @@ flo_lt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1557
 #if MSC_VERSION_BEFORE(1300)
     if (isnan(a)) return Qfalse;
 #endif
-    return (a < b)?Qtrue:Qfalse;
+    return RBOOL(a < b);
 }
 
 /*
@@ -1602,7 +1594,7 @@ flo_le(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1594
 #if MSC_VERSION_BEFORE(1300)
     if (isnan(a)) return Qfalse;
 #endif
-    return (a <= b)?Qtrue:Qfalse;
+    return RBOOL(a <= b);
 }
 
 /*
@@ -1627,8 +1619,7 @@ rb_float_eql(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1619
 #if MSC_VERSION_BEFORE(1300)
 	if (isnan(a) || isnan(b)) return Qfalse;
 #endif
-	if (a == b)
-	    return Qtrue;
+    return RBOOL(a == b);
     }
     return Qfalse;
 }
@@ -4094,8 +4085,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L4085
 fix_gt(VALUE x, VALUE y)
 {
     if (FIXNUM_P(y)) {
-	if (FIX2LONG(x) > FIX2LONG(y)) return Qtrue;
-	return Qfalse;
+        return RBOOL(FIX2LONG(x) > FIX2LONG(y));
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
 	return RBOOL(rb_big_cmp(y, x) == INT2FIX(-1));
@@ -4133,8 +4123,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L4123
 fix_ge(VALUE x, VALUE y)
 {
     if (FIXNUM_P(y)) {
-	if (FIX2LONG(x) >= FIX2LONG(y)) return Qtrue;
-	return Qfalse;
+        return RBOOL(FIX2LONG(x) >= FIX2LONG(y));
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
 	return RBOOL(rb_big_cmp(y, x) != INT2FIX(+1));
@@ -4172,8 +4161,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L4161
 fix_lt(VALUE x, VALUE y)
 {
     if (FIXNUM_P(y)) {
-	if (FIX2LONG(x) < FIX2LONG(y)) return Qtrue;
-	return Qfalse;
+        return RBOOL(FIX2LONG(x) < FIX2LONG(y));
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
 	return RBOOL(rb_big_cmp(y, x) == INT2FIX(+1));
@@ -4211,8 +4199,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L4199
 fix_le(VALUE x, VALUE y)
 {
     if (FIXNUM_P(y)) {
-	if (FIX2LONG(x) <= FIX2LONG(y)) return Qtrue;
-	return Qfalse;
+        return RBOOL(FIX2LONG(x) <= FIX2LONG(y));
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
 	return RBOOL(rb_big_cmp(y, x) != INT2FIX(-1));
diff --git a/re.c b/re.c
index 2afa824..5c5b53d 100644
--- a/re.c
+++ b/re.c
@@ -1724,8 +1724,7 @@ rb_reg_nth_defined(int nth, VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L1724
 	nth += regs->num_regs;
 	if (nth <= 0) return Qnil;
     }
-    if (BEG(nth) == -1) return Qfalse;
-    return Qtrue;
+    return RBOOL(BEG(nth) != -1);
 }
 
 VALUE
@@ -3053,10 +3052,7 @@ rb_reg_equal(VALUE re1, VALUE re2) https://github.com/ruby/ruby/blob/trunk/re.c#L3052
     if (RREGEXP_PTR(re1)->options != RREGEXP_PTR(re2)->options) return Qfalse;
     if (RREGEXP_SRC_LEN(re1) != RREGEXP_SRC_LEN(re2)) return Qfalse;
     if (ENCODING_GET(re1) != ENCODING_GET(re2)) return Qfalse;
-    if (memcmp(RREGEXP_SRC_PTR(re1 (... truncated)

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

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