clean_up_rb_interns.patch

Charlie Somerville, 12/04/2012 06:54 PM

Download (16.1 KB)

View differences:

array.c
28 28

  
29 29
VALUE rb_cArray;
30 30

  
31
static ID id_cmp, id_div, id_power;
31
static ID id_cmp, id_div, id_power, id_sort_by, id_to_ary;
32 32

  
33 33
#define ARY_DEFAULT_SIZE 16
34 34
#define ARY_MAX_SIZE (LONG_MAX / (int)sizeof(VALUE))
......
2501 2501

  
2502 2502
    RETURN_SIZED_ENUMERATOR(ary, 0, 0, rb_ary_length);
2503 2503
    rb_ary_modify(ary);
2504
    sorted = rb_block_call(ary, rb_intern("sort_by"), 0, 0, sort_by_i, 0);
2504
    sorted = rb_block_call(ary, id_sort_by, 0, 0, sort_by_i, 0);
2505 2505
    rb_ary_replace(ary, sorted);
2506 2506
    return ary;
2507 2507
}
......
3571 3571
{
3572 3572
    if (ary1 == ary2) return Qtrue;
3573 3573
    if (!RB_TYPE_P(ary2, T_ARRAY)) {
3574
	if (!rb_respond_to(ary2, rb_intern("to_ary"))) {
3574
	if (!rb_respond_to(ary2, id_to_ary)) {
3575 3575
	    return Qfalse;
3576 3576
	}
3577 3577
	return rb_equal(ary2, ary1);
......
5532 5532
    rb_define_method(rb_cArray, "drop_while", rb_ary_drop_while, 0);
5533 5533
    rb_define_method(rb_cArray, "bsearch", rb_ary_bsearch, 0);
5534 5534

  
5535
    id_cmp = rb_intern("<=>");
5536
    sym_random = ID2SYM(rb_intern("random"));
5537
    id_div = rb_intern("div");
5538
    id_power = rb_intern("**");
5535
    id_cmp      = rb_intern("<=>");
5536
    sym_random  = ID2SYM(rb_intern("random"));
5537
    id_div      = rb_intern("div");
5538
    id_power    = rb_intern("**");
5539
    id_sort_by  = rb_intern("sort_by");
5540
    id_to_ary   = rb_intern("to_ary");
5539 5541
}
bignum.c
13 13
#include "ruby/thread.h"
14 14
#include "ruby/util.h"
15 15
#include "internal.h"
16
#include "id.h"
16 17

  
17 18
#ifdef HAVE_STRINGS_H
18 19
#include <strings.h>
......
1544 1545
        return rb_integer_float_cmp(x, y);
1545 1546

  
1546 1547
      default:
1547
	return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
1548
	return rb_num_coerce_cmp(x, y, idCmp);
1548 1549
    }
1549 1550

  
1550 1551
    if (RBIGNUM_SIGN(x) > RBIGNUM_SIGN(y)) return INT2FIX(1);
......
1591 1592
	{
1592 1593
	    ID id = 0;
1593 1594
	    switch (op) {
1594
		case big_op_gt: id = '>'; break;
1595
		case big_op_ge: id = rb_intern(">="); break;
1596
		case big_op_lt: id = '<'; break;
1597
		case big_op_le: id = rb_intern("<="); break;
1595
		case big_op_gt: id = idGT; break;
1596
		case big_op_ge: id = idGE; break;
1597
		case big_op_lt: id = idLT; break;
1598
		case big_op_le: id = idLE; break;
1598 1599
	    }
1599 1600
	    return rb_num_coerce_relop(x, y, id);
1600 1601
	}
......
2900 2901
VALUE
2901 2902
rb_big_div(VALUE x, VALUE y)
2902 2903
{
2903
    return rb_big_divide(x, y, '/');
2904
    return rb_big_divide(x, y, idDIV);
2904 2905
}
2905 2906

  
2906 2907
/*
......
3159 3160
      case T_FLOAT:
3160 3161
	d = RFLOAT_VALUE(y);
3161 3162
	if ((!RBIGNUM_SIGN(x) && !BIGZEROP(x)) && d != round(d))
3162
	    return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
3163
	    return rb_funcall(rb_complex_raw1(x), idPow, 1, y);
3163 3164
	break;
3164 3165

  
3165 3166
      case T_BIGNUM:
......
3171 3172
	yy = FIX2LONG(y);
3172 3173

  
3173 3174
	if (yy < 0)
3174
	    return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
3175
	    return rb_funcall(rb_rational_raw1(x), idPow, 1, y);
3175 3176
	else {
3176 3177
	    VALUE z = 0;
3177 3178
	    SIGNED_VALUE mask;
......
3196 3197
	break;
3197 3198

  
3198 3199
      default:
3199
	return rb_num_coerce_bin(x, y, rb_intern("**"));
3200
	return rb_num_coerce_bin(x, y, idPow);
3200 3201
    }
3201 3202
    return DBL2NUM(pow(rb_big2dbl(x), d));
3202 3203
}
complex.c
22 22
    id_denominator, id_divmod, id_eqeq_p, id_expt, id_fdiv,  id_floor,
23 23
    id_idiv, id_imag, id_inspect, id_negate, id_numerator, id_quo,
24 24
    id_real, id_real_p, id_to_f, id_to_i, id_to_r, id_to_s,
25
    id_i_real, id_i_imag;
25
    id_i_real, id_i_imag, id_PI;
26 26

  
27 27
#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
28 28

  
......
1972 1972
    return f_mul(self, self);
1973 1973
}
1974 1974

  
1975
#define id_PI rb_intern("PI")
1976

  
1977 1975
/*
1978 1976
 * call-seq:
1979 1977
 *    num.arg    ->  0 or float
......
2112 2110
    id_to_s = rb_intern("to_s");
2113 2111
    id_i_real = rb_intern("@real");
2114 2112
    id_i_imag = rb_intern("@image"); /* @image, not @imag */
2113
    id_PI = rb_intern("PI");
2115 2114

  
2116 2115
    rb_cComplex = rb_define_class("Complex", rb_cNumeric);
2117 2116

  
numeric.c
986 986
	    double dx = RFLOAT_VALUE(x);
987 987
	    double dy = RFLOAT_VALUE(y);
988 988
	    if (dx < 0 && dy != round(dy))
989
		return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
989
		return rb_funcall(rb_complex_raw1(x), idPow, 1, y);
990 990
	    return DBL2NUM(pow(dx, dy));
991 991
	}
992 992
      default:
993
	return rb_num_coerce_bin(x, y, rb_intern("**"));
993
	return rb_num_coerce_bin(x, y, idPow);
994 994
    }
995 995
}
996 996

  
......
1148 1148
	    if (a > 0.0) return INT2FIX(1);
1149 1149
	    return INT2FIX(-1);
1150 1150
	}
1151
	return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
1151
	return rb_num_coerce_cmp(x, y, idCmp);
1152 1152
    }
1153 1153
    return rb_dbl_cmp(a, b);
1154 1154
}
......
1228 1228
	break;
1229 1229

  
1230 1230
      default:
1231
	return rb_num_coerce_relop(x, y, rb_intern(">="));
1231
	return rb_num_coerce_relop(x, y, idGE);
1232 1232
    }
1233 1233
#if defined(_MSC_VER) && _MSC_VER < 1300
1234 1234
    if (isnan(a)) return Qfalse;
......
1311 1311
	break;
1312 1312

  
1313 1313
      default:
1314
	return rb_num_coerce_relop(x, y, rb_intern("<="));
1314
	return rb_num_coerce_relop(x, y, idLE);
1315 1315
    }
1316 1316
#if defined(_MSC_VER) && _MSC_VER < 1300
1317 1317
    if (isnan(a)) return Qfalse;
......
1550 1550
    h = rb_funcall(f, '/', 1, INT2FIX(2));
1551 1551
    r = rb_funcall(num, '%', 1, f);
1552 1552
    n = rb_funcall(num, '-', 1, r);
1553
    op = negative_int_p(num) ? rb_intern("<=") : '<';
1553
    op = negative_int_p(num) ? idLE : '<';
1554 1554
    if (!RTEST(rb_funcall(r, op, 1, h))) {
1555 1555
	n = rb_funcall(n, '+', 1, f);
1556 1556
    }
......
2944 2944
	long b = FIX2LONG(y);
2945 2945

  
2946 2946
	if (b < 0)
2947
	    return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
2947
	    return rb_funcall(rb_rational_raw1(x), idPow, 1, y);
2948 2948

  
2949 2949
	if (b == 0) return INT2FIX(1);
2950 2950
	if (b == 1) return x;
......
2965 2965
      case T_BIGNUM:
2966 2966

  
2967 2967
	if (negative_int_p(y))
2968
	    return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
2968
	    return rb_funcall(rb_rational_raw1(x), idPow, 1, y);
2969 2969

  
2970 2970
	if (a == 0) return INT2FIX(0);
2971 2971
	if (a == 1) return INT2FIX(1);
......
2984 2984
	{
2985 2985
	    double dy = RFLOAT_VALUE(y);
2986 2986
	    if (a < 0 && dy != round(dy))
2987
		return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
2987
		return rb_funcall(rb_complex_raw1(x), idPow, 1, y);
2988 2988
	    return DBL2NUM(pow((double)a, dy));
2989 2989
	}
2990 2990
      default:
2991
	return rb_num_coerce_bin(x, y, rb_intern("**"));
2991
	return rb_num_coerce_bin(x, y, idPow);
2992 2992
    }
2993 2993
}
2994 2994

  
......
3042 3042
      case T_FLOAT:
3043 3043
        return rb_integer_float_cmp(x, y);
3044 3044
      default:
3045
	return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
3045
	return rb_num_coerce_cmp(x, y, idCmp);
3046 3046
    }
3047 3047
}
3048 3048

  
......
3095 3095
          return rel == INT2FIX(1) || rel == INT2FIX(0) ? Qtrue : Qfalse;
3096 3096
        }
3097 3097
      default:
3098
	return rb_num_coerce_relop(x, y, rb_intern(">="));
3098
	return rb_num_coerce_relop(x, y, idGE);
3099 3099
    }
3100 3100
}
3101 3101

  
......
3148 3148
          return rel == INT2FIX(-1) || rel == INT2FIX(0) ? Qtrue : Qfalse;
3149 3149
        }
3150 3150
      default:
3151
	return rb_num_coerce_relop(x, y, rb_intern("<="));
3151
	return rb_num_coerce_relop(x, y, idLE);
3152 3152
    }
3153 3153
}
3154 3154

  
random.c
60 60
*/
61 61

  
62 62
#include "ruby/ruby.h"
63
#include "id.h"
63 64

  
64 65
#include <limits.h>
65 66
#ifdef HAVE_UNISTD_H
......
1256 1257
    if (rb_obj_class(self) != rb_obj_class(other)) return Qfalse;
1257 1258
    r1 = get_rnd(self);
1258 1259
    r2 = get_rnd(other);
1259
    if (!RTEST(rb_funcall2(r1->seed, rb_intern("=="), 1, &r2->seed))) return Qfalse;
1260
    if (!RTEST(rb_funcall2(r1->seed, idEq, 1, &r2->seed))) return Qfalse;
1260 1261
    if (memcmp(r1->mt.state, r2->mt.state, sizeof(r1->mt.state))) return Qfalse;
1261 1262
    if ((r1->mt.next - r1->mt.state) != (r2->mt.next - r2->mt.state)) return Qfalse;
1262 1263
    if (r1->mt.left != r2->mt.left) return Qfalse;
string.c
870 870
    ENC_CODERANGE_SET(str, cr);
871 871
}
872 872

  
873
static ID id_to_s;
873
static ID id_to_s, id_to_str;
874 874

  
875 875
VALUE
876 876
rb_obj_as_string(VALUE obj)
......
2333 2333
{
2334 2334
    if (str1 == str2) return Qtrue;
2335 2335
    if (!RB_TYPE_P(str2, T_STRING)) {
2336
	if (!rb_respond_to(str2, rb_intern("to_str"))) {
2336
	if (!rb_respond_to(str2, id_to_str)) {
2337 2337
	    return Qfalse;
2338 2338
	}
2339 2339
	return rb_equal(str2, str1);
......
2385 2385
    int result;
2386 2386

  
2387 2387
    if (!RB_TYPE_P(str2, T_STRING)) {
2388
	VALUE tmp = rb_check_funcall(str2, rb_intern("to_str"), 0, 0);
2388
	VALUE tmp = rb_check_funcall(str2, id_to_str, 0, 0);
2389 2389
	if (RB_TYPE_P(tmp, T_STRING)) {
2390 2390
	    result = rb_str_cmp(str1, tmp);
2391 2391
	}
2392
	else if ((tmp = rb_check_funcall(str2, rb_intern("<=>"), 1, &str1)) ==
2392
	else if ((tmp = rb_check_funcall(str2, idCmp, 1, &str1)) ==
2393 2393
		 Qundef) {
2394 2394
	    return Qnil;
2395 2395
	}
......
2739 2739

  
2740 2740
      generic:
2741 2741
      default:
2742
	return rb_funcall(y, rb_intern("=~"), 1, x);
2742
	return rb_funcall(y, idEqTilde, 1, x);
2743 2743
    }
2744 2744
}
2745 2745

  
......
3141 3141
	    }
3142 3142
	}
3143 3143
	else {
3144
	    ID op = excl ? '<' : rb_intern("<=");
3144
	    ID op = excl ? '<' : idLE;
3145 3145
	    VALUE args[2], fmt = rb_obj_freeze(rb_usascii_str_new_cstr("%.*d"));
3146 3146

  
3147 3147
	    args[0] = INT2FIX(width);
......
7257 7257
                sum = rb_funcall(sum, '+', 1, LONG2FIX(sum0));
7258 7258
            }
7259 7259

  
7260
            mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits));
7260
            mod = rb_funcall(INT2FIX(1), idLTLT, 1, INT2FIX(bits));
7261 7261
            mod = rb_funcall(mod, '-', 1, INT2FIX(1));
7262 7262
            sum = rb_funcall(sum, '&', 1, mod);
7263 7263
        }
......
8261 8261
    rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
8262 8262

  
8263 8263
    id_to_s = rb_intern("to_s");
8264
    id_to_str = rb_intern("to_str");
8264 8265

  
8265 8266
    rb_fs = Qnil;
8266 8267
    rb_define_variable("$;", &rb_fs);
thread.c
63 63
VALUE rb_cMutex;
64 64
VALUE rb_cThreadShield;
65 65

  
66
static ID id_immediate, id_on_blocking, id_defer;
67

  
66 68
static void sleep_timeval(rb_thread_t *th, struct timeval time, int spurious_check);
67 69
static void sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec, int spurious_check);
68 70
static void sleep_forever(rb_thread_t *th, int nodeadlock, int spurious_check);
......
1457 1459
	    VALUE klass = ancestors_ptr[j];
1458 1460
	    VALUE sym;
1459 1461

  
1460
	    /* TODO: remove rb_intern() */
1461 1462
	    if ((sym = rb_hash_aref(mask, klass)) != Qnil) {
1462
		if (sym == ID2SYM(rb_intern("immediate"))) {
1463
		if (sym == ID2SYM(id_immediate)) {
1463 1464
		    return INTERRUPT_IMMEDIATE;
1464 1465
		}
1465
		else if (sym == ID2SYM(rb_intern("on_blocking"))) {
1466
		else if (sym == ID2SYM(id_on_blocking)) {
1466 1467
		    return INTERRUPT_ON_BLOCKING;
1467 1468
		}
1468
		else if (sym == ID2SYM(rb_intern("defer"))) {
1469
		else if (sym == ID2SYM(id_defer)) {
1469 1470
		    return INTERRUPT_DEFER;
1470 1471
		}
1471 1472
		else {
......
1556 1557
static int
1557 1558
async_interrupt_timing_arg_check_i(VALUE key, VALUE val)
1558 1559
{
1559
    VALUE immediate = ID2SYM(rb_intern("immediate"));
1560
    VALUE on_blocking = ID2SYM(rb_intern("on_blocking"));
1561
    VALUE defer = ID2SYM(rb_intern("defer"));
1560
    VALUE immediate = ID2SYM(id_immediate);
1561
    VALUE on_blocking = ID2SYM(id_on_blocking);
1562
    VALUE defer = ID2SYM(id_defer);
1562 1563

  
1563 1564
    if (val != immediate && val != on_blocking && val != defer) {
1564 1565
	rb_raise(rb_eArgError, "unknown mask signature");
......
4876 4877
    rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize_m, 0);
4877 4878

  
4878 4879
    recursive_key = rb_intern("__recursive_key__");
4880
    id_immediate = rb_intern("immediate");
4881
    id_on_blocking = rb_intern("on_blocking");
4882
    id_defer = rb_intern("defer");
4879 4883
    rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
4880 4884

  
4881 4885
    /* init thread core */
time.c
29 29

  
30 30
#include "timev.h"
31 31

  
32
static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset;
33
static ID id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift;
32
static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset,
33
	id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift, id_to_r, id_to_str,
34
	id_dst, id_std;
34 35

  
35 36
#define NDIV(x,y) (-(-((x)+1)/(y))-1)
36 37
#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
......
678 679
        goto typeerror;
679 680

  
680 681
      default:
681
        if ((tmp = rb_check_funcall(v, rb_intern("to_r"), 0, NULL)) != Qundef) {
682
            if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror;
682
        if ((tmp = rb_check_funcall(v, id_to_r, 0, NULL)) != Qundef) {
683
            if (rb_respond_to(v, id_to_str)) goto typeerror;
683 684
            v = tmp;
684 685
            break;
685 686
        }
......
2186 2187
    vtm.utc_offset = Qnil;
2187 2188
    if (!NIL_P(v[6])) {
2188 2189
        VALUE arg = v[6];
2189
        if (arg == ID2SYM(rb_intern("dst")))
2190
        if (arg == ID2SYM(id_dst))
2190 2191
            vtm.isdst = 1;
2191
        else if (arg == ID2SYM(rb_intern("std")))
2192
        else if (arg == ID2SYM(id_std))
2192 2193
            vtm.isdst = 0;
2193 2194
        else
2194 2195
            vtm.utc_offset = utc_offset_arg(arg);
......
3361 3362
    else {
3362 3363
	VALUE tmp;
3363 3364

  
3364
	tmp = rb_funcall(time2, rb_intern("<=>"), 1, time1);
3365
	tmp = rb_funcall(time2, id_cmp, 1, time1);
3365 3366
	if (NIL_P(tmp)) return Qnil;
3366 3367

  
3367 3368
	n = -rb_cmpint(tmp, time1, time2);
......
4955 4956
    id_nano_num = rb_intern("nano_num");
4956 4957
    id_nano_den = rb_intern("nano_den");
4957 4958
    id_offset = rb_intern("offset");
4959
    id_to_r = rb_intern("to_r");
4960
    id_to_str = rb_intern("to_str");
4961
    id_dst = rb_intern("dst");
4962
    id_std = rb_intern("std");
4958 4963

  
4959 4964
    rb_cTime = rb_define_class("Time", rb_cObject);
4960 4965
    rb_include_module(rb_cTime, rb_mComparable);
vm_eval.c
19 19
static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t *base_block);
20 20
static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary);
21 21

  
22
static ID id_message, id_call;
23

  
22 24
/* vm_backtrace.c */
23 25
VALUE vm_backtrace_str_ary(rb_thread_t *th, int lev, int n);
24 26

  
......
592 594
    if (!format) {
593 595
	format = "undefined method `%s' for %s";
594 596
    }
595
    mesg = rb_const_get(exc, rb_intern("message"));
597
    mesg = rb_const_get(exc, id_message);
596 598
    if (rb_method_basic_definition_p(CLASS_OF(mesg), '!')) {
597 599
	args[n++] = rb_name_err_mesg_new(mesg, rb_str_new2(format), obj, argv[0]);
598 600
    }
......
1391 1393
	PUSH_TAG();
1392 1394
	rb_set_safe_level_force(level);
1393 1395
	if ((state = EXEC_TAG()) == 0) {
1394
	    val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg),
1396
	    val = rb_funcall2(cmd, id_call, RARRAY_LENINT(arg),
1395 1397
			      RARRAY_PTR(arg));
1396 1398
	}
1397 1399
	POP_TAG();
......
1876 1878
    rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1);
1877 1879
    rb_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1);
1878 1880

  
1881
    id_message = rb_intern("message");
1882
    id_call = rb_intern("call");
1883

  
1879 1884
#if 1
1880 1885
    rb_add_method(rb_cBasicObject, rb_intern("__send__"),
1881 1886
		  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);