From 4ea5c5610aeadecf78fdd2b7d6faad8574953620 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 3 Aug 2019 08:37:08 +0900 Subject: Predefine some IDs --- bignum.c | 6 +++--- complex.c | 6 +++--- defs/id.def | 5 +++++ enum.c | 3 +-- error.c | 4 ++-- numeric.c | 13 ++++++------- rational.c | 9 +++++---- time.c | 15 +++++++-------- 8 files changed, 32 insertions(+), 29 deletions(-) diff --git a/bignum.c b/bignum.c index 212d19abdf..2818b05b1e 100644 --- a/bignum.c +++ b/bignum.c @@ -6082,7 +6082,7 @@ rb_big_div(VALUE x, VALUE y) VALUE rb_big_idiv(VALUE x, VALUE y) { - return rb_big_divide(x, y, rb_intern("div")); + return rb_big_divide(x, y, idDiv); } VALUE @@ -6126,7 +6126,7 @@ rb_big_divmod(VALUE x, VALUE y) y = rb_int2big(FIX2LONG(y)); } else if (!RB_BIGNUM_TYPE_P(y)) { - return rb_num_coerce_bin(x, y, rb_intern("divmod")); + return rb_num_coerce_bin(x, y, idDivmod); } bigdivmod(x, y, &div, &mod); @@ -6214,7 +6214,7 @@ rb_big_fdiv_double(VALUE x, VALUE y) return big_fdiv_float(x, y); } else { - return NUM2DBL(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); + return NUM2DBL(rb_num_coerce_bin(x, y, idFdiv)); } v = rb_flo_div_flo(DBL2NUM(dx), DBL2NUM(dy)); return NUM2DBL(v); diff --git a/complex.c b/complex.c index fa00036ffb..4c51d1a2d6 100644 --- a/complex.c +++ b/complex.c @@ -33,7 +33,7 @@ extern int signbit(double); VALUE rb_cComplex; static ID id_abs, id_arg, - id_denominator, id_fdiv, id_numerator, id_quo, + id_denominator, id_numerator, id_real_p, id_i_real, id_i_imag, id_finite_p, id_infinite_p, id_rationalize, id_PI; @@ -42,6 +42,8 @@ static ID id_abs, id_arg, #define id_negate idUMinus #define id_expt idPow #define id_to_f idTo_f +#define id_quo idQuo +#define id_fdiv idFdiv #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -2278,9 +2280,7 @@ Init_Complex(void) id_abs = rb_intern("abs"); id_arg = rb_intern("arg"); id_denominator = rb_intern("denominator"); - id_fdiv = rb_intern("fdiv"); id_numerator = rb_intern("numerator"); - id_quo = rb_intern("quo"); id_real_p = rb_intern("real?"); id_i_real = rb_intern("@real"); id_i_imag = rb_intern("@image"); /* @image, not @imag */ diff --git a/defs/id.def b/defs/id.def index 25677ffdc2..1296b12e6c 100644 --- a/defs/id.def +++ b/defs/id.def @@ -49,6 +49,11 @@ firstline, predefined = __LINE__+1, %[\ not NOT and AND or OR + div + divmod + fdiv + quo + name _ UScore "/*NULL*/" NULL diff --git a/enum.c b/enum.c index c06e336d2f..f97a2d108b 100644 --- a/enum.c +++ b/enum.c @@ -21,8 +21,8 @@ VALUE rb_mEnumerable; static ID id_next; -static ID id_div; +#define id_div idDiv #define id_each idEach #define id_eqq idEqq #define id_cmp idCmp @@ -4201,5 +4201,4 @@ Init_Enumerable(void) rb_define_method(rb_mEnumerable, "uniq", enum_uniq, 0); id_next = rb_intern("next"); - id_div = rb_intern("div"); } diff --git a/error.c b/error.c index 00ee6df5b9..8834100cfd 100644 --- a/error.c +++ b/error.c @@ -884,12 +884,13 @@ static VALUE rb_eNOERROR; ID ruby_static_id_cause; #define id_cause ruby_static_id_cause static ID id_message, id_backtrace; -static ID id_name, id_key, id_args, id_Errno, id_errno, id_i_path; +static ID id_key, id_args, id_Errno, id_errno, id_i_path; static ID id_receiver, id_recv, id_iseq, id_local_variables; static ID id_private_call_p, id_top, id_bottom; #define id_bt idBt #define id_bt_locations idBt_locations #define id_mesg idMesg +#define id_name idName #undef rb_exc_new_cstr @@ -2538,7 +2539,6 @@ Init_Exception(void) id_cause = rb_intern_const("cause"); id_message = rb_intern_const("message"); id_backtrace = rb_intern_const("backtrace"); - id_name = rb_intern_const("name"); id_key = rb_intern_const("key"); id_args = rb_intern_const("args"); id_receiver = rb_intern_const("receiver"); diff --git a/numeric.c b/numeric.c index 7ce6590bfd..2f5da6f887 100644 --- a/numeric.c +++ b/numeric.c @@ -171,7 +171,9 @@ static VALUE flo_to_i(VALUE num); static int float_round_overflow(int ndigits, int binexp); static int float_round_underflow(int ndigits, int binexp); -static ID id_coerce, id_div, id_divmod; +static ID id_coerce; +#define id_div idDiv +#define id_divmod idDivmod #define id_to_i idTo_i #define id_eq idEq #define id_cmp idCmp @@ -3717,7 +3719,7 @@ fix_fdiv_double(VALUE x, VALUE y) return double_div_double(FIX2LONG(x), RFLOAT_VALUE(y)); } else { - return NUM2DBL(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); + return NUM2DBL(rb_num_coerce_bin(x, y, idFdiv)); } } @@ -5561,8 +5563,8 @@ Init_Numeric(void) _set_Creg(0, 0); #endif id_coerce = rb_intern("coerce"); - id_div = rb_intern("div"); - id_divmod = rb_intern("divmod"); + id_to = rb_intern("to"); + id_by = rb_intern("by"); rb_eZeroDivError = rb_define_class("ZeroDivisionError", rb_eStandardError); rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError); @@ -5821,9 +5823,6 @@ Init_Numeric(void) rb_define_method(rb_cFloat, "prev_float", flo_prev_float, 0); rb_define_method(rb_cFloat, "positive?", flo_positive_p, 0); rb_define_method(rb_cFloat, "negative?", flo_negative_p, 0); - - id_to = rb_intern("to"); - id_by = rb_intern("by"); } #undef rb_float_value diff --git a/rational.c b/rational.c index ed7e356749..d032cbd5a7 100644 --- a/rational.c +++ b/rational.c @@ -33,8 +33,10 @@ VALUE rb_cRational; -static ID id_abs, id_idiv, id_integer_p, +static ID id_abs, id_integer_p, id_i_num, id_i_den; + +#define id_idiv idDiv #define id_to_i idTo_i #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -1601,7 +1603,7 @@ f_ceil(VALUE x) return rb_funcall(x, id_ceil, 0); } -#define id_quo rb_intern("quo") +#define id_quo idQuo static VALUE f_quo(VALUE x, VALUE y) { @@ -2013,7 +2015,7 @@ VALUE rb_numeric_quo(VALUE x, VALUE y) { if (RB_FLOAT_TYPE_P(y)) { - return rb_funcall(x, rb_intern("fdiv"), 1, y); + return rb_funcallv(x, idFdiv, 1, &y); } if (canonicalization) { @@ -2711,7 +2713,6 @@ Init_Rational(void) #define rb_intern(str) rb_intern_const(str) id_abs = rb_intern("abs"); - id_idiv = rb_intern("div"); id_integer_p = rb_intern("integer?"); id_i_num = rb_intern("@numerator"); id_i_den = rb_intern("@denominator"); diff --git a/time.c b/time.c index 7f39799bed..91e7d9d709 100644 --- a/time.c +++ b/time.c @@ -35,11 +35,14 @@ #include "timev.h" #include "id.h" -static ID id_divmod, id_submicro, id_nano_num, id_nano_den, id_offset, id_zone; -static ID id_quo, id_div; +static ID id_submicro, id_nano_num, id_nano_den, id_offset, id_zone; static ID id_nanosecond, id_microsecond, id_millisecond, id_nsec, id_usec; static ID id_local_to_utc, id_utc_to_local, id_find_timezone; -static ID id_year, id_mon, id_mday, id_hour, id_min, id_sec, id_isdst, id_name; +static ID id_year, id_mon, id_mday, id_hour, id_min, id_sec, id_isdst; +#define id_quo idQuo +#define id_div idDiv +#define id_divmod idDivmod +#define id_name idName #define UTC_ZONE Qundef #ifndef TM_IS_TIME @@ -5600,7 +5603,7 @@ rb_time_zone_abbreviation(VALUE zone, VALUE time) if (abbr != Qundef) { goto found; } - abbr = rb_check_funcall_default(zone, rb_intern("name"), 0, 0, Qnil); + abbr = rb_check_funcall_default(zone, idName, 0, 0, Qnil); found: return rb_obj_as_string(abbr); } @@ -5740,9 +5743,6 @@ Init_Time(void) #undef rb_intern #define rb_intern(str) rb_intern_const(str) - id_quo = rb_intern("quo"); - id_div = rb_intern("div"); - id_divmod = rb_intern("divmod"); id_submicro = rb_intern("submicro"); id_nano_num = rb_intern("nano_num"); id_nano_den = rb_intern("nano_den"); @@ -5762,7 +5762,6 @@ Init_Time(void) id_min = rb_intern("min"); id_sec = rb_intern("sec"); id_isdst = rb_intern("isdst"); - id_name = rb_intern("name"); id_find_timezone = rb_intern("find_timezone"); rb_cTime = rb_define_class("Time", rb_cObject); -- cgit v1.2.3