Refactor and Using RBOOL macro

This commit is contained in:
S.H 2021-09-15 08:11:05 +09:00 коммит произвёл GitHub
Родитель 89242279e6
Коммит b8c3a84bdd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 34 добавлений и 90 удалений

Просмотреть файл

@ -5387,18 +5387,14 @@ rb_integer_float_eq(VALUE x, VALUE y)
if (FIXNUM_P(x)) { if (FIXNUM_P(x)) {
#if SIZEOF_LONG * CHAR_BIT < DBL_MANT_DIG /* assume FLT_RADIX == 2 */ #if SIZEOF_LONG * CHAR_BIT < DBL_MANT_DIG /* assume FLT_RADIX == 2 */
double xd = (double)FIX2LONG(x); double xd = (double)FIX2LONG(x);
if (xd != yd) return RBOOL(xd == yd);
return Qfalse;
return Qtrue;
#else #else
long xn, yn; long xn, yn;
if (yi < LONG_MIN || LONG_MAX_as_double <= yi) if (yi < LONG_MIN || LONG_MAX_as_double <= yi)
return Qfalse; return Qfalse;
xn = FIX2LONG(x); xn = FIX2LONG(x);
yn = (long)yi; yn = (long)yi;
if (xn != yn) return RBOOL(xn == yn);
return Qfalse;
return Qtrue;
#endif #endif
} }
y = rb_dbl2big(yi); y = rb_dbl2big(yi);
@ -5527,8 +5523,7 @@ rb_big_eq(VALUE x, VALUE y)
} }
if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse; if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse;
if (BIGNUM_LEN(x) != BIGNUM_LEN(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 RBOOL(MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) == 0);
return Qtrue;
} }
VALUE VALUE
@ -5537,8 +5532,7 @@ rb_big_eql(VALUE x, VALUE y)
if (!RB_BIGNUM_TYPE_P(y)) return Qfalse; if (!RB_BIGNUM_TYPE_P(y)) return Qfalse;
if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse; if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse;
if (BIGNUM_LEN(x) != BIGNUM_LEN(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 RBOOL(MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) == 0);
return Qtrue;
} }
VALUE VALUE
@ -6821,10 +6815,7 @@ rb_big_bit_length(VALUE big)
VALUE VALUE
rb_big_odd_p(VALUE num) rb_big_odd_p(VALUE num)
{ {
if (BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) { return RBOOL(BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1);
return Qtrue;
}
return Qfalse;
} }
VALUE VALUE

Просмотреть файл

@ -84,8 +84,7 @@ cmp_equal(VALUE x, VALUE y)
c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y); c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);
if (NIL_P(c)) return Qfalse; if (NIL_P(c)) return Qfalse;
if (rb_cmpint(c, x, y) == 0) return Qtrue; return RBOOL(rb_cmpint(c, x, y) == 0);
return Qfalse;
} }
static int static int

Просмотреть файл

@ -1451,10 +1451,7 @@ rb_complex_finite_p(VALUE self)
{ {
get_dat1(self); get_dat1(self);
if (f_finite_p(dat->real) && f_finite_p(dat->imag)) { return RBOOL(f_finite_p(dat->real) && f_finite_p(dat->imag));
return Qtrue;
}
return Qfalse;
} }
/* /*

Просмотреть файл

@ -1548,9 +1548,7 @@ exc_equal(VALUE exc, VALUE obj)
if (!rb_equal(rb_attr_get(exc, id_mesg), mesg)) if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
return Qfalse; return Qfalse;
if (!rb_equal(exc_backtrace(exc), backtrace)) return rb_equal(exc_backtrace(exc), backtrace);
return Qfalse;
return Qtrue;
} }
/* /*
@ -1638,10 +1636,7 @@ exit_success_p(VALUE exc)
if (NIL_P(status_val)) if (NIL_P(status_val))
return Qtrue; return Qtrue;
status = NUM2INT(status_val); status = NUM2INT(status_val);
if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
return Qtrue;
return Qfalse;
} }
static VALUE static VALUE

15
file.c
Просмотреть файл

@ -2019,8 +2019,7 @@ rb_file_file_p(VALUE obj, VALUE fname)
struct stat st; struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse; if (rb_stat(fname, &st) < 0) return Qfalse;
if (S_ISREG(st.st_mode)) return Qtrue; return RBOOL(S_ISREG(st.st_mode));
return Qfalse;
} }
/* /*
@ -2039,8 +2038,7 @@ rb_file_zero_p(VALUE obj, VALUE fname)
struct stat st; struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse; if (rb_stat(fname, &st) < 0) return Qfalse;
if (st.st_size == 0) return Qtrue; return RBOOL(st.st_size == 0);
return Qfalse;
} }
/* /*
@ -2080,8 +2078,7 @@ rb_file_owned_p(VALUE obj, VALUE fname)
struct stat st; struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse; if (rb_stat(fname, &st) < 0) return Qfalse;
if (st.st_uid == geteuid()) return Qtrue; return RBOOL(st.st_uid == geteuid());
return Qfalse;
} }
static VALUE static VALUE
@ -2090,8 +2087,7 @@ rb_file_rowned_p(VALUE obj, VALUE fname)
struct stat st; struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse; if (rb_stat(fname, &st) < 0) return Qfalse;
if (st.st_uid == getuid()) return Qtrue; return RBOOL(st.st_uid == getuid());
return Qfalse;
} }
/* /*
@ -2124,8 +2120,7 @@ check3rdbyte(VALUE fname, int mode)
struct stat st; struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse; if (rb_stat(fname, &st) < 0) return Qfalse;
if (st.st_mode & mode) return Qtrue; return RBOOL(st.st_mode & mode);
return Qfalse;
} }
#endif #endif

Просмотреть файл

@ -755,18 +755,10 @@ static VALUE
int_zero_p(VALUE num) int_zero_p(VALUE num)
{ {
if (FIXNUM_P(num)) { if (FIXNUM_P(num)) {
if (FIXNUM_ZERO_P(num)) { return RBOOL(FIXNUM_ZERO_P(num));
return Qtrue;
} }
}
else {
assert(RB_BIGNUM_TYPE_P(num)); assert(RB_BIGNUM_TYPE_P(num));
if (rb_bigzero_p(num)) { return RBOOL(rb_bigzero_p(num));
/* this should not happen usually */
return Qtrue;
}
}
return Qfalse;
} }
VALUE VALUE
@ -1368,7 +1360,7 @@ rb_float_equal(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300) #if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse; if (isnan(a)) return Qfalse;
#endif #endif
return (a == b)?Qtrue:Qfalse; return RBOOL(a == b);
} }
#define flo_eq rb_float_equal #define flo_eq rb_float_equal
@ -1491,7 +1483,7 @@ rb_float_gt(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300) #if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse; if (isnan(a)) return Qfalse;
#endif #endif
return (a > b)?Qtrue:Qfalse; return RBOOL(a > b);
} }
/* /*
@ -1528,7 +1520,7 @@ flo_ge(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300) #if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse; if (isnan(a)) return Qfalse;
#endif #endif
return (a >= b)?Qtrue:Qfalse; return RBOOL(a >= b);
} }
/* /*
@ -1565,7 +1557,7 @@ flo_lt(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300) #if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse; if (isnan(a)) return Qfalse;
#endif #endif
return (a < b)?Qtrue:Qfalse; return RBOOL(a < b);
} }
/* /*
@ -1602,7 +1594,7 @@ flo_le(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300) #if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse; if (isnan(a)) return Qfalse;
#endif #endif
return (a <= b)?Qtrue:Qfalse; return RBOOL(a <= b);
} }
/* /*
@ -1627,8 +1619,7 @@ rb_float_eql(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300) #if MSC_VERSION_BEFORE(1300)
if (isnan(a) || isnan(b)) return Qfalse; if (isnan(a) || isnan(b)) return Qfalse;
#endif #endif
if (a == b) return RBOOL(a == b);
return Qtrue;
} }
return Qfalse; return Qfalse;
} }
@ -4094,8 +4085,7 @@ static VALUE
fix_gt(VALUE x, VALUE y) fix_gt(VALUE x, VALUE y)
{ {
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(x) > FIX2LONG(y)) return Qtrue; return RBOOL(FIX2LONG(x) > FIX2LONG(y));
return Qfalse;
} }
else if (RB_BIGNUM_TYPE_P(y)) { else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) == INT2FIX(-1)); return RBOOL(rb_big_cmp(y, x) == INT2FIX(-1));
@ -4133,8 +4123,7 @@ static VALUE
fix_ge(VALUE x, VALUE y) fix_ge(VALUE x, VALUE y)
{ {
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(x) >= FIX2LONG(y)) return Qtrue; return RBOOL(FIX2LONG(x) >= FIX2LONG(y));
return Qfalse;
} }
else if (RB_BIGNUM_TYPE_P(y)) { else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) != INT2FIX(+1)); return RBOOL(rb_big_cmp(y, x) != INT2FIX(+1));
@ -4172,8 +4161,7 @@ static VALUE
fix_lt(VALUE x, VALUE y) fix_lt(VALUE x, VALUE y)
{ {
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(x) < FIX2LONG(y)) return Qtrue; return RBOOL(FIX2LONG(x) < FIX2LONG(y));
return Qfalse;
} }
else if (RB_BIGNUM_TYPE_P(y)) { else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) == INT2FIX(+1)); return RBOOL(rb_big_cmp(y, x) == INT2FIX(+1));
@ -4211,8 +4199,7 @@ static VALUE
fix_le(VALUE x, VALUE y) fix_le(VALUE x, VALUE y)
{ {
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(x) <= FIX2LONG(y)) return Qtrue; return RBOOL(FIX2LONG(x) <= FIX2LONG(y));
return Qfalse;
} }
else if (RB_BIGNUM_TYPE_P(y)) { else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) != INT2FIX(-1)); return RBOOL(rb_big_cmp(y, x) != INT2FIX(-1));

8
re.c
Просмотреть файл

@ -1724,8 +1724,7 @@ rb_reg_nth_defined(int nth, VALUE match)
nth += regs->num_regs; nth += regs->num_regs;
if (nth <= 0) return Qnil; if (nth <= 0) return Qnil;
} }
if (BEG(nth) == -1) return Qfalse; return RBOOL(BEG(nth) != -1);
return Qtrue;
} }
VALUE VALUE
@ -3053,10 +3052,7 @@ rb_reg_equal(VALUE re1, VALUE re2)
if (RREGEXP_PTR(re1)->options != RREGEXP_PTR(re2)->options) return Qfalse; if (RREGEXP_PTR(re1)->options != RREGEXP_PTR(re2)->options) return Qfalse;
if (RREGEXP_SRC_LEN(re1) != RREGEXP_SRC_LEN(re2)) return Qfalse; if (RREGEXP_SRC_LEN(re1) != RREGEXP_SRC_LEN(re2)) return Qfalse;
if (ENCODING_GET(re1) != ENCODING_GET(re2)) return Qfalse; if (ENCODING_GET(re1) != ENCODING_GET(re2)) return Qfalse;
if (memcmp(RREGEXP_SRC_PTR(re1), RREGEXP_SRC_PTR(re2), RREGEXP_SRC_LEN(re1)) == 0) { return RBOOL(memcmp(RREGEXP_SRC_PTR(re1), RREGEXP_SRC_PTR(re2), RREGEXP_SRC_LEN(re1)) == 0);
return Qtrue;
}
return Qfalse;
} }
/* /*

Просмотреть файл

@ -4630,8 +4630,7 @@ rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive)
if (ISASCII(b) && ISASCII(e) && ISASCII(v)) { if (ISASCII(b) && ISASCII(e) && ISASCII(v)) {
if (b <= v && v < e) return Qtrue; if (b <= v && v < e) return Qtrue;
if (!RTEST(exclusive) && v == e) return Qtrue; return RBOOL(!RTEST(exclusive) && v == e);
return Qfalse;
} }
} }
} }

Просмотреть файл

@ -3370,13 +3370,7 @@ rb_thread_stop_p(VALUE thread)
if (rb_threadptr_dead(th)) { if (rb_threadptr_dead(th)) {
return Qtrue; return Qtrue;
} }
else if (th->status == THREAD_STOPPED || return RBOOL(th->status == THREAD_STOPPED || th->status == THREAD_STOPPED_FOREVER);
th->status == THREAD_STOPPED_FOREVER) {
return Qtrue;
}
else {
return Qfalse;
}
} }
/* /*
@ -3770,12 +3764,7 @@ rb_thread_key_p(VALUE self, VALUE key)
if (!id || local_storage == NULL) { if (!id || local_storage == NULL) {
return Qfalse; return Qfalse;
} }
else if (rb_id_table_lookup(local_storage, id, &val)) { return RBOOL(rb_id_table_lookup(local_storage, id, &val));
return Qtrue;
}
else {
return Qfalse;
}
} }
static enum rb_id_table_iterator_result static enum rb_id_table_iterator_result

Просмотреть файл

@ -783,8 +783,7 @@ MJIT_FUNC_EXPORTED VALUE
rb_gvar_defined(ID id) rb_gvar_defined(ID id)
{ {
struct rb_global_entry *entry = rb_global_entry(id); struct rb_global_entry *entry = rb_global_entry(id);
if (entry->var->getter == rb_gvar_undef_getter) return Qfalse; return RBOOL(entry->var->getter != rb_gvar_undef_getter);
return Qtrue;
} }
rb_gvar_getter_t * rb_gvar_getter_t *
@ -1099,10 +1098,7 @@ generic_ivar_defined(VALUE obj, ID id)
if (!iv_index_tbl_lookup(iv_index_tbl, id, &index)) return Qfalse; if (!iv_index_tbl_lookup(iv_index_tbl, id, &index)) return Qfalse;
if (!gen_ivtbl_get(obj, id, &ivtbl)) return Qfalse; if (!gen_ivtbl_get(obj, id, &ivtbl)) return Qfalse;
if ((index < ivtbl->numiv) && (ivtbl->ivptr[index] != Qundef)) return RBOOL((index < ivtbl->numiv) && (ivtbl->ivptr[index] != Qundef));
return Qtrue;
return Qfalse;
} }
static int static int