diff --git array.c array.c index 3bbf935..e49732d 100644 --- array.c +++ array.c @@ -28,7 +28,7 @@ VALUE rb_cArray; -static ID id_cmp, id_div, id_power; +static ID id_cmp, id_div, id_power, id_sort_by, id_to_ary; #define ARY_DEFAULT_SIZE 16 #define ARY_MAX_SIZE (LONG_MAX / (int)sizeof(VALUE)) @@ -2501,7 +2501,7 @@ rb_ary_sort_by_bang(VALUE ary) RETURN_SIZED_ENUMERATOR(ary, 0, 0, rb_ary_length); rb_ary_modify(ary); - sorted = rb_block_call(ary, rb_intern("sort_by"), 0, 0, sort_by_i, 0); + sorted = rb_block_call(ary, id_sort_by, 0, 0, sort_by_i, 0); rb_ary_replace(ary, sorted); return ary; } @@ -3571,7 +3571,7 @@ rb_ary_equal(VALUE ary1, VALUE ary2) { if (ary1 == ary2) return Qtrue; if (!RB_TYPE_P(ary2, T_ARRAY)) { - if (!rb_respond_to(ary2, rb_intern("to_ary"))) { + if (!rb_respond_to(ary2, id_to_ary)) { return Qfalse; } return rb_equal(ary2, ary1); @@ -5532,8 +5532,10 @@ Init_Array(void) rb_define_method(rb_cArray, "drop_while", rb_ary_drop_while, 0); rb_define_method(rb_cArray, "bsearch", rb_ary_bsearch, 0); - id_cmp = rb_intern("<=>"); - sym_random = ID2SYM(rb_intern("random")); - id_div = rb_intern("div"); - id_power = rb_intern("**"); + id_cmp = rb_intern("<=>"); + sym_random = ID2SYM(rb_intern("random")); + id_div = rb_intern("div"); + id_power = rb_intern("**"); + id_sort_by = rb_intern("sort_by"); + id_to_ary = rb_intern("to_ary"); } diff --git bignum.c bignum.c index 6663057..ed11dba 100644 --- bignum.c +++ bignum.c @@ -13,6 +13,7 @@ #include "ruby/thread.h" #include "ruby/util.h" #include "internal.h" +#include "id.h" #ifdef HAVE_STRINGS_H #include @@ -1544,7 +1545,7 @@ rb_big_cmp(VALUE x, VALUE y) return rb_integer_float_cmp(x, y); default: - return rb_num_coerce_cmp(x, y, rb_intern("<=>")); + return rb_num_coerce_cmp(x, y, idCmp); } if (RBIGNUM_SIGN(x) > RBIGNUM_SIGN(y)) return INT2FIX(1); @@ -1591,10 +1592,10 @@ big_op(VALUE x, VALUE y, enum big_op_t op) { ID id = 0; switch (op) { - case big_op_gt: id = '>'; break; - case big_op_ge: id = rb_intern(">="); break; - case big_op_lt: id = '<'; break; - case big_op_le: id = rb_intern("<="); break; + case big_op_gt: id = idGT; break; + case big_op_ge: id = idGE; break; + case big_op_lt: id = idLT; break; + case big_op_le: id = idLE; break; } return rb_num_coerce_relop(x, y, id); } @@ -2900,7 +2901,7 @@ rb_big_divide(VALUE x, VALUE y, ID op) VALUE rb_big_div(VALUE x, VALUE y) { - return rb_big_divide(x, y, '/'); + return rb_big_divide(x, y, idDIV); } /* @@ -3159,7 +3160,7 @@ rb_big_pow(VALUE x, VALUE y) case T_FLOAT: d = RFLOAT_VALUE(y); if ((!RBIGNUM_SIGN(x) && !BIGZEROP(x)) && d != round(d)) - return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y); + return rb_funcall(rb_complex_raw1(x), idPow, 1, y); break; case T_BIGNUM: @@ -3171,7 +3172,7 @@ rb_big_pow(VALUE x, VALUE y) yy = FIX2LONG(y); if (yy < 0) - return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y); + return rb_funcall(rb_rational_raw1(x), idPow, 1, y); else { VALUE z = 0; SIGNED_VALUE mask; @@ -3196,7 +3197,7 @@ rb_big_pow(VALUE x, VALUE y) break; default: - return rb_num_coerce_bin(x, y, rb_intern("**")); + return rb_num_coerce_bin(x, y, idPow); } return DBL2NUM(pow(rb_big2dbl(x), d)); } diff --git complex.c complex.c index 2efe6a4..b19ecf2 100644 --- complex.c +++ complex.c @@ -22,7 +22,7 @@ static ID id_abs, id_abs2, id_arg, id_cmp, id_conj, id_convert, id_denominator, id_divmod, id_eqeq_p, id_expt, id_fdiv, id_floor, id_idiv, id_imag, id_inspect, id_negate, id_numerator, id_quo, id_real, id_real_p, id_to_f, id_to_i, id_to_r, id_to_s, - id_i_real, id_i_imag; + id_i_real, id_i_imag, id_PI; #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -1972,8 +1972,6 @@ numeric_abs2(VALUE self) return f_mul(self, self); } -#define id_PI rb_intern("PI") - /* * call-seq: * num.arg -> 0 or float @@ -2112,6 +2110,7 @@ Init_Complex(void) id_to_s = rb_intern("to_s"); id_i_real = rb_intern("@real"); id_i_imag = rb_intern("@image"); /* @image, not @imag */ + id_PI = rb_intern("PI"); rb_cComplex = rb_define_class("Complex", rb_cNumeric); diff --git numeric.c numeric.c index c2562f4..0634d21 100644 --- numeric.c +++ numeric.c @@ -986,11 +986,11 @@ flo_pow(VALUE x, VALUE y) double dx = RFLOAT_VALUE(x); double dy = RFLOAT_VALUE(y); if (dx < 0 && dy != round(dy)) - return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y); + return rb_funcall(rb_complex_raw1(x), idPow, 1, y); return DBL2NUM(pow(dx, dy)); } default: - return rb_num_coerce_bin(x, y, rb_intern("**")); + return rb_num_coerce_bin(x, y, idPow); } } @@ -1148,7 +1148,7 @@ flo_cmp(VALUE x, VALUE y) if (a > 0.0) return INT2FIX(1); return INT2FIX(-1); } - return rb_num_coerce_cmp(x, y, rb_intern("<=>")); + return rb_num_coerce_cmp(x, y, idCmp); } return rb_dbl_cmp(a, b); } @@ -1228,7 +1228,7 @@ flo_ge(VALUE x, VALUE y) break; default: - return rb_num_coerce_relop(x, y, rb_intern(">=")); + return rb_num_coerce_relop(x, y, idGE); } #if defined(_MSC_VER) && _MSC_VER < 1300 if (isnan(a)) return Qfalse; @@ -1311,7 +1311,7 @@ flo_le(VALUE x, VALUE y) break; default: - return rb_num_coerce_relop(x, y, rb_intern("<=")); + return rb_num_coerce_relop(x, y, idLE); } #if defined(_MSC_VER) && _MSC_VER < 1300 if (isnan(a)) return Qfalse; @@ -1550,7 +1550,7 @@ int_round_0(VALUE num, int ndigits) h = rb_funcall(f, '/', 1, INT2FIX(2)); r = rb_funcall(num, '%', 1, f); n = rb_funcall(num, '-', 1, r); - op = negative_int_p(num) ? rb_intern("<=") : '<'; + op = negative_int_p(num) ? idLE : '<'; if (!RTEST(rb_funcall(r, op, 1, h))) { n = rb_funcall(n, '+', 1, f); } @@ -2944,7 +2944,7 @@ fix_pow(VALUE x, VALUE y) long b = FIX2LONG(y); if (b < 0) - return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y); + return rb_funcall(rb_rational_raw1(x), idPow, 1, y); if (b == 0) return INT2FIX(1); if (b == 1) return x; @@ -2965,7 +2965,7 @@ fix_pow(VALUE x, VALUE y) case T_BIGNUM: if (negative_int_p(y)) - return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y); + return rb_funcall(rb_rational_raw1(x), idPow, 1, y); if (a == 0) return INT2FIX(0); if (a == 1) return INT2FIX(1); @@ -2984,11 +2984,11 @@ fix_pow(VALUE x, VALUE y) { double dy = RFLOAT_VALUE(y); if (a < 0 && dy != round(dy)) - return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y); + return rb_funcall(rb_complex_raw1(x), idPow, 1, y); return DBL2NUM(pow((double)a, dy)); } default: - return rb_num_coerce_bin(x, y, rb_intern("**")); + return rb_num_coerce_bin(x, y, idPow); } } @@ -3042,7 +3042,7 @@ fix_cmp(VALUE x, VALUE y) case T_FLOAT: return rb_integer_float_cmp(x, y); default: - return rb_num_coerce_cmp(x, y, rb_intern("<=>")); + return rb_num_coerce_cmp(x, y, idCmp); } } @@ -3095,7 +3095,7 @@ fix_ge(VALUE x, VALUE y) return rel == INT2FIX(1) || rel == INT2FIX(0) ? Qtrue : Qfalse; } default: - return rb_num_coerce_relop(x, y, rb_intern(">=")); + return rb_num_coerce_relop(x, y, idGE); } } @@ -3148,7 +3148,7 @@ fix_le(VALUE x, VALUE y) return rel == INT2FIX(-1) || rel == INT2FIX(0) ? Qtrue : Qfalse; } default: - return rb_num_coerce_relop(x, y, rb_intern("<=")); + return rb_num_coerce_relop(x, y, idLE); } } diff --git random.c random.c index 50db6ec..160cf1b 100644 --- random.c +++ random.c @@ -60,6 +60,7 @@ The original copyright notice follows. */ #include "ruby/ruby.h" +#include "id.h" #include #ifdef HAVE_UNISTD_H @@ -1256,7 +1257,7 @@ random_equal(VALUE self, VALUE other) if (rb_obj_class(self) != rb_obj_class(other)) return Qfalse; r1 = get_rnd(self); r2 = get_rnd(other); - if (!RTEST(rb_funcall2(r1->seed, rb_intern("=="), 1, &r2->seed))) return Qfalse; + if (!RTEST(rb_funcall2(r1->seed, idEq, 1, &r2->seed))) return Qfalse; if (memcmp(r1->mt.state, r2->mt.state, sizeof(r1->mt.state))) return Qfalse; if ((r1->mt.next - r1->mt.state) != (r2->mt.next - r2->mt.state)) return Qfalse; if (r1->mt.left != r2->mt.left) return Qfalse; diff --git string.c string.c index 4666176..5ba2941 100644 --- string.c +++ string.c @@ -870,7 +870,7 @@ rb_str_shared_replace(VALUE str, VALUE str2) ENC_CODERANGE_SET(str, cr); } -static ID id_to_s; +static ID id_to_s, id_to_str; VALUE rb_obj_as_string(VALUE obj) @@ -2333,7 +2333,7 @@ rb_str_equal(VALUE str1, VALUE str2) { if (str1 == str2) return Qtrue; if (!RB_TYPE_P(str2, T_STRING)) { - if (!rb_respond_to(str2, rb_intern("to_str"))) { + if (!rb_respond_to(str2, id_to_str)) { return Qfalse; } return rb_equal(str2, str1); @@ -2385,11 +2385,11 @@ rb_str_cmp_m(VALUE str1, VALUE str2) int result; if (!RB_TYPE_P(str2, T_STRING)) { - VALUE tmp = rb_check_funcall(str2, rb_intern("to_str"), 0, 0); + VALUE tmp = rb_check_funcall(str2, id_to_str, 0, 0); if (RB_TYPE_P(tmp, T_STRING)) { result = rb_str_cmp(str1, tmp); } - else if ((tmp = rb_check_funcall(str2, rb_intern("<=>"), 1, &str1)) == + else if ((tmp = rb_check_funcall(str2, idCmp, 1, &str1)) == Qundef) { return Qnil; } @@ -2739,7 +2739,7 @@ rb_str_match(VALUE x, VALUE y) generic: default: - return rb_funcall(y, rb_intern("=~"), 1, x); + return rb_funcall(y, idEqTilde, 1, x); } } @@ -3141,7 +3141,7 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg) } } else { - ID op = excl ? '<' : rb_intern("<="); + ID op = excl ? '<' : idLE; VALUE args[2], fmt = rb_obj_freeze(rb_usascii_str_new_cstr("%.*d")); args[0] = INT2FIX(width); @@ -7257,7 +7257,7 @@ rb_str_sum(int argc, VALUE *argv, VALUE str) sum = rb_funcall(sum, '+', 1, LONG2FIX(sum0)); } - mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits)); + mod = rb_funcall(INT2FIX(1), idLTLT, 1, INT2FIX(bits)); mod = rb_funcall(mod, '-', 1, INT2FIX(1)); sum = rb_funcall(sum, '&', 1, mod); } @@ -8261,6 +8261,7 @@ Init_String(void) rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0); id_to_s = rb_intern("to_s"); + id_to_str = rb_intern("to_str"); rb_fs = Qnil; rb_define_variable("$;", &rb_fs); diff --git thread.c thread.c index b1127a7..11376a2 100644 --- thread.c +++ thread.c @@ -63,6 +63,8 @@ VALUE rb_cMutex; VALUE rb_cThreadShield; +static ID id_immediate, id_on_blocking, id_defer; + static void sleep_timeval(rb_thread_t *th, struct timeval time, int spurious_check); static void sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec, int spurious_check); static void sleep_forever(rb_thread_t *th, int nodeadlock, int spurious_check); @@ -1457,15 +1459,14 @@ rb_threadptr_async_errinfo_check_mask(rb_thread_t *th, VALUE err) VALUE klass = ancestors_ptr[j]; VALUE sym; - /* TODO: remove rb_intern() */ if ((sym = rb_hash_aref(mask, klass)) != Qnil) { - if (sym == ID2SYM(rb_intern("immediate"))) { + if (sym == ID2SYM(id_immediate)) { return INTERRUPT_IMMEDIATE; } - else if (sym == ID2SYM(rb_intern("on_blocking"))) { + else if (sym == ID2SYM(id_on_blocking)) { return INTERRUPT_ON_BLOCKING; } - else if (sym == ID2SYM(rb_intern("defer"))) { + else if (sym == ID2SYM(id_defer)) { return INTERRUPT_DEFER; } else { @@ -1556,9 +1557,9 @@ rb_threadptr_async_errinfo_active_p(rb_thread_t *th) static int async_interrupt_timing_arg_check_i(VALUE key, VALUE val) { - VALUE immediate = ID2SYM(rb_intern("immediate")); - VALUE on_blocking = ID2SYM(rb_intern("on_blocking")); - VALUE defer = ID2SYM(rb_intern("defer")); + VALUE immediate = ID2SYM(id_immediate); + VALUE on_blocking = ID2SYM(id_on_blocking); + VALUE defer = ID2SYM(id_defer); if (val != immediate && val != on_blocking && val != defer) { rb_raise(rb_eArgError, "unknown mask signature"); @@ -4876,6 +4877,9 @@ Init_Thread(void) rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize_m, 0); recursive_key = rb_intern("__recursive_key__"); + id_immediate = rb_intern("immediate"); + id_on_blocking = rb_intern("on_blocking"); + id_defer = rb_intern("defer"); rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError); /* init thread core */ diff --git time.c time.c index 846ff3d..707d5eb 100644 --- time.c +++ time.c @@ -29,8 +29,9 @@ #include "timev.h" -static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset; -static ID id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift; +static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset, + id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift, id_to_r, id_to_str, + id_dst, id_std; #define NDIV(x,y) (-(-((x)+1)/(y))-1) #define NMOD(x,y) ((y)-(-((x)+1)%(y))-1) @@ -678,8 +679,8 @@ num_exact(VALUE v) goto typeerror; default: - if ((tmp = rb_check_funcall(v, rb_intern("to_r"), 0, NULL)) != Qundef) { - if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror; + if ((tmp = rb_check_funcall(v, id_to_r, 0, NULL)) != Qundef) { + if (rb_respond_to(v, id_to_str)) goto typeerror; v = tmp; break; } @@ -2186,9 +2187,9 @@ time_init_1(int argc, VALUE *argv, VALUE time) vtm.utc_offset = Qnil; if (!NIL_P(v[6])) { VALUE arg = v[6]; - if (arg == ID2SYM(rb_intern("dst"))) + if (arg == ID2SYM(id_dst)) vtm.isdst = 1; - else if (arg == ID2SYM(rb_intern("std"))) + else if (arg == ID2SYM(id_std)) vtm.isdst = 0; else vtm.utc_offset = utc_offset_arg(arg); @@ -3361,7 +3362,7 @@ time_cmp(VALUE time1, VALUE time2) else { VALUE tmp; - tmp = rb_funcall(time2, rb_intern("<=>"), 1, time1); + tmp = rb_funcall(time2, id_cmp, 1, time1); if (NIL_P(tmp)) return Qnil; n = -rb_cmpint(tmp, time1, time2); @@ -4955,6 +4956,10 @@ Init_Time(void) id_nano_num = rb_intern("nano_num"); id_nano_den = rb_intern("nano_den"); id_offset = rb_intern("offset"); + id_to_r = rb_intern("to_r"); + id_to_str = rb_intern("to_str"); + id_dst = rb_intern("dst"); + id_std = rb_intern("std"); rb_cTime = rb_define_class("Time", rb_cObject); rb_include_module(rb_cTime, rb_mComparable); diff --git vm_eval.c vm_eval.c index f0b0c50..8688e36 100644 --- vm_eval.c +++ vm_eval.c @@ -19,6 +19,8 @@ static VALUE vm_exec(rb_thread_t *th); static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t *base_block); static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary); +static ID id_message, id_call; + /* vm_backtrace.c */ VALUE vm_backtrace_str_ary(rb_thread_t *th, int lev, int n); @@ -592,7 +594,7 @@ make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, con if (!format) { format = "undefined method `%s' for %s"; } - mesg = rb_const_get(exc, rb_intern("message")); + mesg = rb_const_get(exc, id_message); if (rb_method_basic_definition_p(CLASS_OF(mesg), '!')) { args[n++] = rb_name_err_mesg_new(mesg, rb_str_new2(format), obj, argv[0]); } @@ -1391,7 +1393,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level) PUSH_TAG(); rb_set_safe_level_force(level); if ((state = EXEC_TAG()) == 0) { - val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg), + val = rb_funcall2(cmd, id_call, RARRAY_LENINT(arg), RARRAY_PTR(arg)); } POP_TAG(); @@ -1876,6 +1878,9 @@ Init_vm_eval(void) rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1); rb_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1); + id_message = rb_intern("message"); + id_call = rb_intern("call"); + #if 1 rb_add_method(rb_cBasicObject, rb_intern("__send__"), VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);