summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-09 09:25:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-09 09:25:32 +0000
commit5a647a3f5fd011f8558c7f9e90cd65e70e73eb40 (patch)
tree294dcb47e83e5480b1fa992aba8a4b4025c8a626
parent250dd0702111d5c2086f007b1b31ecc1e36ade40 (diff)
* include/ruby/ruby.h (CONST_ID): constant ID cache for non-gcc.
* *.c: no cache in init functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--array.c2
-rw-r--r--blockinlining.c26
-rw-r--r--class.c12
-rw-r--r--compar.c2
-rw-r--r--compile.c22
-rw-r--r--complex.c2
-rw-r--r--encoding.c6
-rw-r--r--enum.c4
-rw-r--r--error.c13
-rw-r--r--eval.c2
-rw-r--r--file.c7
-rw-r--r--hash.c2
-rw-r--r--id.c2
-rw-r--r--include/ruby/ruby.h16
-rw-r--r--io.c10
-rw-r--r--iseq.c12
-rw-r--r--marshal.c2
-rw-r--r--numeric.c2
-rw-r--r--object.c2
-rw-r--r--parse.y4
-rw-r--r--prec.c2
-rw-r--r--range.c2
-rw-r--r--rational.c2
-rw-r--r--ruby.c3
-rw-r--r--string.c4
-rw-r--r--thread.c2
-rw-r--r--time.c2
-rw-r--r--variable.c10
-rw-r--r--vm.c14
-rw-r--r--vm_dump.c27
-rw-r--r--vm_method.c2
32 files changed, 141 insertions, 85 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a7f614..3727381 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Jun 9 18:25:30 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/ruby.h (CONST_ID): constant ID cache for non-gcc.
+
+ * *.c: no cache in init functions.
+
Mon Jun 9 17:56:30 2008 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb (Set#delete_if): Call to_a.
diff --git a/array.c b/array.c
index fdf1808..fef44e4 100644
--- a/array.c
+++ b/array.c
@@ -3400,6 +3400,8 @@ rb_ary_drop_while(VALUE ary)
void
Init_Array(void)
{
+#undef rb_intern
+
rb_cArray = rb_define_class("Array", rb_cObject);
rb_include_module(rb_cArray, rb_mEnumerable);
diff --git a/blockinlining.c b/blockinlining.c
index c2878d9..3f4aa86 100644
--- a/blockinlining.c
+++ b/blockinlining.c
@@ -129,9 +129,11 @@ build_Integer_times_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
end
}
*/
- ID _self = rb_intern("#_self");
+ ID _self;
+ CONST_ID(_self, "#_self");
if (iseq->argc == 0) {
- ID e = rb_intern("#e");
+ ID e;
+ CONST_ID(e, "#e");
rb_ary_push(param_vars, ID2SYM(e));
rb_ary_push(param_vars, ID2SYM(_self));
iseq->argc += 2;
@@ -145,10 +147,11 @@ build_Integer_times_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
Qundef);
}
else {
- ID _e = rb_intern("#_e");
+ ID _e;
ID e = SYM2ID(rb_ary_entry(param_vars, 0));
NODE *assign;
+ CONST_ID(_e, "#_e");
rb_ary_push(param_vars, ID2SYM(_self));
rb_ary_push(local_vars, ID2SYM(_e));
iseq->argc++;
@@ -230,9 +233,11 @@ build_Range_each_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
end
}
*/
- ID _last = rb_intern("#_last");
+ ID _last;
+ CONST_ID(_last, "#_last");
if (iseq->argc == 0) {
- ID e = rb_intern("#e");
+ ID e;
+ CONST_ID(e, "#e");
rb_ary_push(param_vars, ID2SYM(e));
rb_ary_push(param_vars, ID2SYM(_last));
iseq->argc += 2;
@@ -245,10 +250,11 @@ build_Range_each_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
Qundef);
}
else {
- ID _e = rb_intern("#_e");
+ ID _e;
ID e = SYM2ID(rb_ary_entry(param_vars, 0));
NODE *assign;
+ CONST_ID(_e, "#_e");
rb_ary_push(param_vars, ID2SYM(_last));
rb_ary_push(local_vars, ID2SYM(_e));
iseq->argc++;
@@ -362,11 +368,13 @@ build_Array_each_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
}
*/
- ID _self = rb_intern("#_self");
- ID _i = rb_intern("#_i");
+ ID _self, _i;
+ CONST_ID(_self, "#_self");
+ CONST_ID(_i, "#_i");
if (iseq->argc == 0) {
- ID _e = rb_intern("#_e");
+ ID _e;
+ CONST_ID(_e, "#_e");
rb_ary_push(param_vars, ID2SYM(_e));
rb_ary_push(param_vars, ID2SYM(_self));
iseq->argc += 2;
diff --git a/class.c b/class.c
index 60bd2e3..0d612a5 100644
--- a/class.c
+++ b/class.c
@@ -102,9 +102,9 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
ID id;
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
- id = rb_intern("__classpath__");
+ CONST_ID(id, "__classpath__");
st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
- id = rb_intern("__classid__");
+ CONST_ID(id, "__classid__");
st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
}
if (RCLASS_M_TBL(orig)) {
@@ -169,10 +169,12 @@ void
rb_singleton_class_attached(VALUE klass, VALUE obj)
{
if (FL_TEST(klass, FL_SINGLETON)) {
+ ID attached;
if (!RCLASS_IV_TBL(klass)) {
RCLASS_IV_TBL(klass) = st_init_numtable();
}
- st_insert(RCLASS_IV_TBL(klass), rb_intern("__attached__"), obj);
+ CONST_ID(attached, "__attached__");
+ st_insert(RCLASS_IV_TBL(klass), attached, obj);
}
}
@@ -214,8 +216,10 @@ rb_define_class_id(ID id, VALUE super)
VALUE
rb_class_inherited(VALUE super, VALUE klass)
{
+ ID inherited;
if (!super) super = rb_cObject;
- return rb_funcall(super, rb_intern("inherited"), 1, klass);
+ CONST_ID(inherited, "inherited");
+ return rb_funcall(super, inherited, 1, klass);
}
VALUE
diff --git a/compar.c b/compar.c
index 55b217a..b028a25 100644
--- a/compar.c
+++ b/compar.c
@@ -198,6 +198,8 @@ cmp_between(VALUE x, VALUE min, VALUE max)
void
Init_Comparable(void)
{
+#undef rb_intern
+
rb_mComparable = rb_define_module("Comparable");
rb_define_method(rb_mComparable, "==", cmp_equal, 1);
rb_define_method(rb_mComparable, ">", cmp_gt, 1);
diff --git a/compile.c b/compile.c
index 7362a0e..0424a83 100644
--- a/compile.c
+++ b/compile.c
@@ -761,11 +761,9 @@ iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
static int
iseq_set_exception_local_table(rb_iseq_t *iseq)
{
- static ID id_dollar_bang;
+ ID id_dollar_bang;
- if (!id_dollar_bang) {
- id_dollar_bang = rb_intern("#$!");
- }
+ CONST_ID(id_dollar_bang, "#$!");
iseq->local_table = (ID *)ALLOC_N(ID *, 1);
iseq->local_table_size = 1;
iseq->local_size = iseq->local_table_size + 1;
@@ -3718,15 +3716,14 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
}
/* only joke */
{
- static ID goto_id;
- static ID label_id;
+ ID goto_id;
+ ID label_id;
VALUE label;
VALUE label_sym;
- if (goto_id == 0) {
- goto_id = rb_intern("__goto__");
- label_id = rb_intern("__label__");
- }
+
+ CONST_ID(goto_id, "__goto__");
+ CONST_ID(label_id, "__label__");
if (nd_type(node) == NODE_FCALL &&
(mid == goto_id || mid == label_id)) {
@@ -4319,14 +4316,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
break;
}
case NODE_SCLASS:{
+ ID singletonclass;
VALUE iseqval =
NEW_ISEQVAL(node->nd_body, rb_str_new2("singletonclass"),
ISEQ_TYPE_CLASS);
COMPILE(ret, "sclass#recv", node->nd_recv);
ADD_INSN (ret, nd_line(node), putnil);
+ CONST_ID(singletonclass, "singletonclass");
ADD_INSN3(ret, nd_line(node), defineclass,
- ID2SYM(rb_intern("singletonclass")), iseqval, INT2FIX(1));
+ ID2SYM(singletonclass), iseqval, INT2FIX(1));
if (poped) {
ADD_INSN(ret, nd_line(node), pop);
@@ -4787,6 +4786,7 @@ register_label(rb_iseq_t *iseq, struct st_table *labels_table, VALUE obj)
static VALUE
get_exception_sym2type(VALUE sym)
{
+#undef rb_intern
static VALUE symRescue, symEnsure, symRetry;
static VALUE symBreak, symRedo, symNext;
diff --git a/complex.c b/complex.c
index 16bf8f0..6bc004a 100644
--- a/complex.c
+++ b/complex.c
@@ -1387,6 +1387,8 @@ numeric_conjugate(VALUE self)
void
Init_Complex(void)
{
+#undef rb_intern
+
assert(fprintf(stderr, "assert() is now active\n"));
id_Unify = rb_intern("Unify");
diff --git a/encoding.c b/encoding.c
index b1fc140..0928b4b 100644
--- a/encoding.c
+++ b/encoding.c
@@ -533,9 +533,7 @@ enc_check_capable(VALUE x)
ID
rb_id_encoding(void)
{
- if (!id_encoding) {
- id_encoding = rb_intern("encoding");
- }
+ CONST_ID(id_encoding, "encoding");
return id_encoding;
}
@@ -1162,6 +1160,8 @@ rb_enc_aliases(VALUE klass)
void
Init_Encoding(void)
{
+#undef rb_intern
+
id_base_encoding = rb_intern("#base_encoding");
rb_cEncoding = rb_define_class("Encoding", rb_cObject);
diff --git a/enum.c b/enum.c
index 7a7f180..e4d4ee5 100644
--- a/enum.c
+++ b/enum.c
@@ -1566,7 +1566,7 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
}
}
if (!allary) {
- conv = rb_intern("to_enum");
+ CONST_ID(conv, "to_enum");
for (i=0; i<argc; i++) {
argv[i] = rb_funcall(argv[i], conv, 1, ID2SYM(id_each));
}
@@ -1800,6 +1800,8 @@ enum_cycle(int argc, VALUE *argv, VALUE obj)
void
Init_Enumerable(void)
{
+#undef rb_intern
+
rb_mEnumerable = rb_define_module("Enumerable");
rb_define_method(rb_mEnumerable, "to_a", enum_to_a, -1);
diff --git a/error.c b/error.c
index f339fb3..2210a70 100644
--- a/error.c
+++ b/error.c
@@ -496,9 +496,9 @@ exc_inspect(VALUE exc)
static VALUE
exc_backtrace(VALUE exc)
{
- static ID bt;
+ ID bt;
- if (!bt) bt = rb_intern("bt");
+ CONST_ID(bt, "bt");
return rb_attr_get(exc, bt);
}
@@ -506,7 +506,7 @@ VALUE
rb_check_backtrace(VALUE bt)
{
long i;
- static const char *err = "backtrace must be Array of String";
+ static const char err[] = "backtrace must be Array of String";
if (!NIL_P(bt)) {
int t = TYPE(bt);
@@ -552,11 +552,12 @@ exc_set_backtrace(VALUE exc, VALUE bt)
static VALUE
exc_equal(VALUE exc, VALUE obj)
{
- ID id_mesg = rb_intern("mesg");
+ ID id_mesg;
if (exc == obj) return Qtrue;
if (rb_obj_class(exc) != rb_obj_class(obj))
return rb_equal(obj, exc);
+ CONST_ID(id_mesg, "mesg");
if (!rb_equal(rb_attr_get(exc, id_mesg), rb_attr_get(obj, id_mesg)))
return Qfalse;
if (!rb_equal(exc_backtrace(exc), exc_backtrace(obj)))
@@ -963,7 +964,9 @@ static VALUE
syserr_eqq(VALUE self, VALUE exc)
{
VALUE num, e;
- ID en = rb_intern("errno");
+ ID en;
+
+ CONST_ID(en, "errno");
if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
if (!rb_respond_to(exc, en)) return Qfalse;
diff --git a/eval.c b/eval.c
index 7cd2a22..167dea7 100644
--- a/eval.c
+++ b/eval.c
@@ -507,7 +507,7 @@ rb_make_exception(int argc, VALUE *argv)
case 3:
n = 1;
exception_call:
- exception = rb_intern("exception");
+ CONST_ID(exception, "exception");
if (!rb_respond_to(argv[0], exception)) {
rb_raise(rb_eTypeError, "exception class/object expected");
}
diff --git a/file.c b/file.c
index 1d1fab2..5b99cf0 100644
--- a/file.c
+++ b/file.c
@@ -102,15 +102,14 @@ static VALUE
rb_get_path_check(VALUE obj, int check)
{
VALUE tmp;
- static ID to_path;
+ ID to_path;
if (check) rb_check_safe_obj(obj);
tmp = rb_check_string_type(obj);
if (!NIL_P(tmp)) goto exit;
- if (!to_path) {
- to_path = rb_intern("to_path");
- }
+
+ CONST_ID(to_path, "to_path");
if (rb_respond_to(obj, to_path)) {
tmp = rb_funcall(obj, to_path, 0, 0);
}
diff --git a/hash.c b/hash.c
index b5a0c68..89139e8 100644
--- a/hash.c
+++ b/hash.c
@@ -2564,6 +2564,8 @@ env_update(VALUE env, VALUE hash)
void
Init_Hash(void)
{
+#undef rb_intern
+
id_hash = rb_intern("hash");
id_yield = rb_intern("yield");
id_default = rb_intern("default");
diff --git a/id.c b/id.c
index c5d7e36..0226a9f 100644
--- a/id.c
+++ b/id.c
@@ -18,6 +18,8 @@
void
Init_id(void)
{
+#undef rb_intern
+
/* Symbols */
symIFUNC = ID2SYM(rb_intern("<IFUNC>"));
symCFUNC = ID2SYM(rb_intern("<CFUNC>"));
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 614a614..99321f1 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -764,17 +764,21 @@ const char *rb_id2name(ID);
ID rb_to_id(VALUE);
VALUE rb_id2str(ID);
+#define CONST_ID_CACHE(result, str) \
+ ({ \
+ static ID rb_intern_id_cache; \
+ if (!rb_intern_id_cache) \
+ rb_intern_id_cache = (rb_intern)(str); \
+ result rb_intern_id_cache; \
+ })
+#define CONST_ID(var, str) \
+ do {CONST_ID_CACHE(var =, str);} while (0)
#ifdef __GNUC__
/* __builtin_constant_p and statement expression is available
* since gcc-2.7.2.3 at least. */
#define rb_intern(str) \
(__builtin_constant_p(str) ? \
- ({ \
- static ID rb_intern_id_cache; \
- if (!rb_intern_id_cache) \
- rb_intern_id_cache = rb_intern(str); \
- rb_intern_id_cache; \
- }) : \
+ CONST_ID_CACHE(/**/, str) : \
rb_intern(str))
#endif
diff --git a/io.c b/io.c
index 2cad50c..d5ffa0c 100644
--- a/io.c
+++ b/io.c
@@ -4231,7 +4231,7 @@ rb_f_open(int argc, VALUE *argv)
int redirect = Qfalse;
if (argc >= 1) {
- to_open = rb_intern("to_open");
+ CONST_ID(to_open, "to_open");
if (rb_respond_to(argv[0], to_open)) {
redirect = Qtrue;
}
@@ -6178,11 +6178,11 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
if (!encoding) {
ID id;
- id = rb_intern("encoding");
+ CONST_ID(id, "encoding");
encoding = ID2SYM(id);
- id = rb_intern("mode");
+ CONST_ID(id, "mode");
mode = ID2SYM(id);
- id = rb_intern("open_args");
+ CONST_ID(id, "open_args");
open_args = ID2SYM(id);
}
v = rb_hash_aref(opt, open_args);
@@ -7484,6 +7484,8 @@ rb_get_argv(void)
void
Init_IO(void)
{
+#undef rb_intern
+
VALUE rb_cARGF;
#ifdef __CYGWIN__
#include <sys/cygwin.h>
diff --git a/iseq.c b/iseq.c
index b8a84ed..e09c9c4 100644
--- a/iseq.c
+++ b/iseq.c
@@ -956,12 +956,12 @@ exception_type2symbol(VALUE type)
{
ID id;
switch(type) {
- case CATCH_TYPE_RESCUE: id = rb_intern("rescue"); break;
- case CATCH_TYPE_ENSURE: id = rb_intern("ensure"); break;
- case CATCH_TYPE_RETRY: id = rb_intern("retry"); break;
- case CATCH_TYPE_BREAK: id = rb_intern("break"); break;
- case CATCH_TYPE_REDO: id = rb_intern("redo"); break;
- case CATCH_TYPE_NEXT: id = rb_intern("next"); break;
+ case CATCH_TYPE_RESCUE: CONST_ID(id, "rescue"); break;
+ case CATCH_TYPE_ENSURE: CONST_ID(id, "ensure"); break;
+ case CATCH_TYPE_RETRY: CONST_ID(id, "retry"); break;
+ case CATCH_TYPE_BREAK: CONST_ID(id, "break"); break;
+ case CATCH_TYPE_REDO: CONST_ID(id, "redo"); break;
+ case CATCH_TYPE_NEXT: CONST_ID(id, "next"); break;
default:
rb_bug("...");
}
diff --git a/marshal.c b/marshal.c
index 9f22cdc..692b37d 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1669,6 +1669,8 @@ marshal_load(int argc, VALUE *argv)
void
Init_marshal(void)
{
+#undef rb_intern
+
VALUE rb_mMarshal = rb_define_module("Marshal");
s_dump = rb_intern("_dump");
diff --git a/numeric.c b/numeric.c
index 6374982..318d604 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3092,6 +3092,8 @@ fix_even_p(VALUE num)
void
Init_Numeric(void)
{
+#undef rb_intern
+
#if defined(__FreeBSD__) && __FreeBSD__ < 4
/* allow divide by zero -- Inf */
fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV|FP_X_OFL));
diff --git a/object.c b/object.c
index 70e7f19..0d18ea5 100644
--- a/object.c
+++ b/object.c
@@ -2365,6 +2365,8 @@ boot_defclass(const char *name, VALUE super)
void
Init_Object(void)
{
+#undef rb_intern
+
VALUE metaclass;
rb_cBasicObject = boot_defclass("BasicObject", 0);
diff --git a/parse.y b/parse.y
index 31694a3..48a777e 100644
--- a/parse.y
+++ b/parse.y
@@ -7761,9 +7761,9 @@ assignable_gen(struct parser_params *parser, ID id, NODE *val)
static void
shadowing_lvar_gen(struct parser_params *parser, ID name)
{
- static ID uscore;
+ ID uscore;
- if (!uscore) uscore = rb_intern("_");
+ CONST_ID(uscore, "_");
if (uscore == name) return;
if (dyna_in_block()) {
if (dvar_curr(name)) {
diff --git a/prec.c b/prec.c
index c2e3032..3b24524 100644
--- a/prec.c
+++ b/prec.c
@@ -124,6 +124,8 @@ prec_included(VALUE module, VALUE include)
void
Init_Precision(void)
{
+#undef rb_intern
+
rb_mPrecision = rb_define_module("Precision");
rb_define_singleton_method(rb_mPrecision, "included", prec_included, 1);
rb_define_method(rb_mPrecision, "prec", prec_prec, 1);
diff --git a/range.c b/range.c
index 45ba78d..3b19a2b 100644
--- a/range.c
+++ b/range.c
@@ -896,6 +896,8 @@ range_alloc(VALUE klass)
void
Init_Range(void)
{
+#undef rb_intern
+
id_cmp = rb_intern("<=>");
id_succ = rb_intern("succ");
id_beg = rb_intern("begin");
diff --git a/rational.c b/rational.c
index aaf1d3a..8bf786a 100644
--- a/rational.c
+++ b/rational.c
@@ -1501,6 +1501,8 @@ nurat_s_induced_from(VALUE klass, VALUE n)
void
Init_Rational(void)
{
+#undef rb_intern
+
assert(fprintf(stderr, "assert() is now active\n"));
id_Unify = rb_intern("Unify");
diff --git a/ruby.c b/ruby.c
index f6c3a43..a8945ea 100644
--- a/ruby.c
+++ b/ruby.c
@@ -452,9 +452,10 @@ static void
require_libraries(struct cmdline_options *opt)
{
VALUE list = opt->req_list;
- ID require = rb_intern("require");
+ ID require;
Init_ext(); /* should be called here for some reason :-( */
+ CONST_ID(require, "require");
while (list && RARRAY_LEN(list) > 0) {
VALUE feature = rb_ary_shift(list);
rb_funcall2(rb_vm_top_self(), require, 1, &feature);
diff --git a/string.c b/string.c
index 68a4c55..ef54b7e 100644
--- a/string.c
+++ b/string.c
@@ -2632,7 +2632,7 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg)
rb_scan_args(argc, argv, "11", &end, &exclusive);
excl = RTEST(exclusive);
- succ = rb_intern("succ");
+ CONST_ID(succ, "succ");
StringValue(end);
enc = rb_enc_check(beg, end);
if (RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1 &&
@@ -6526,6 +6526,8 @@ rb_to_id(VALUE name)
void
Init_String(void)
{
+#undef rb_intern
+
rb_cString = rb_define_class("String", rb_cObject);
rb_include_module(rb_cString, rb_mComparable);
rb_define_alloc_func(rb_cString, str_alloc);
diff --git a/thread.c b/thread.c
index 298d1c1..522c786 100644
--- a/thread.c
+++ b/thread.c
@@ -3167,6 +3167,8 @@ ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always)
void
Init_Thread(void)
{
+#undef rb_intern
+
VALUE cThGroup;
rb_define_singleton_method(rb_cThread, "new", thread_s_new, -1);
diff --git a/time.c b/time.c
index f6e9724..c35c9a1 100644
--- a/time.c
+++ b/time.c
@@ -2338,6 +2338,8 @@ time_load(VALUE klass, VALUE str)
void
Init_Time(void)
{
+#undef rb_intern
+
id_divmod = rb_intern("divmod");
id_mul = rb_intern("*");
id_submicro = rb_intern("submicro");
diff --git a/variable.c b/variable.c
index 14cac18..3185d8a 100644
--- a/variable.c
+++ b/variable.c
@@ -26,9 +26,9 @@ Init_var_tables(void)
{
rb_global_tbl = st_init_numtable();
rb_class_tbl = st_init_numtable();
- autoload = rb_intern("__autoload__");
- classpath = rb_intern("__classpath__");
- tmp_classpath = rb_intern("__tmp_classpath__");
+ CONST_ID(autoload, "__autoload__");
+ CONST_ID(classpath, "__classpath__");
+ CONST_ID(tmp_classpath, "__tmp_classpath__");
}
struct fc_result {
@@ -142,7 +142,9 @@ classname(VALUE klass)
if (!klass) klass = rb_cObject;
if (RCLASS_IV_TBL(klass)) {
if (!st_lookup(RCLASS_IV_TBL(klass), classpath, &path)) {
- ID classid = rb_intern("__classid__");
+ ID classid;
+
+ CONST_ID(classid, "__classid__");
if (!st_lookup(RCLASS_IV_TBL(klass), classid, &path)) {
return find_class_path(klass);
diff --git a/vm.c b/vm.c
index a62392c..5ac1e67 100644
--- a/vm.c
+++ b/vm.c
@@ -754,22 +754,22 @@ make_localjump_error(const char *mesg, VALUE value, int reason)
switch (reason) {
case TAG_BREAK:
- id = rb_intern("break");
+ CONST_ID(id, "break");
break;
case TAG_REDO:
- id = rb_intern("redo");
+ CONST_ID(id, "redo");
break;
case TAG_RETRY:
- id = rb_intern("retry");
+ CONST_ID(id, "retry");
break;
case TAG_NEXT:
- id = rb_intern("next");
+ CONST_ID(id, "next");
break;
case TAG_RETURN:
- id = rb_intern("return");
+ CONST_ID(id, "return");
break;
default:
- id = rb_intern("noreason");
+ CONST_ID(id, "noreason");
break;
}
rb_iv_set(exc, "@exit_value", value);
@@ -1241,7 +1241,7 @@ rb_thread_method_id_and_class(rb_thread_t *th,
}
while (iseq) {
if (RUBY_VM_IFUNC_P(iseq)) {
- if (idp) *idp = rb_intern("<ifunc>");
+ if (idp) CONST_ID(*idp, "<ifunc>");
if (klassp) *klassp = 0;
return 1;
}
diff --git a/vm_dump.c b/vm_dump.c
index c9e0657..80bb13e 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -425,18 +425,16 @@ debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp
void
vm_analysis_insn(int insn)
{
- static ID usage_hash;
- static ID bigram_hash;
+ ID usage_hash;
+ ID bigram_hash;
static int prev_insn = -1;
VALUE uh;
VALUE ihash;
VALUE cv;
- if (usage_hash == 0) {
- usage_hash = rb_intern("USAGE_ANALYSIS_INSN");
- bigram_hash = rb_intern("USAGE_ANALYSIS_INSN_BIGRAM");
- }
+ CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
+ CONST_ID(bigram_hash, "USAGE_ANALYSIS_INSN_BIGRAM");
uh = rb_const_get(rb_cVM, usage_hash);
if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
ihash = rb_hash_new();
@@ -473,7 +471,7 @@ extern VALUE insn_operand_intern(int insn, int op_no, VALUE op,
void
vm_analysis_operand(int insn, int n, VALUE op)
{
- static ID usage_hash;
+ ID usage_hash;
VALUE uh;
VALUE ihash;
@@ -481,9 +479,7 @@ vm_analysis_operand(int insn, int n, VALUE op)
VALUE valstr;
VALUE cv;
- if (usage_hash == 0) {
- usage_hash = rb_intern("USAGE_ANALYSIS_INSN");
- }
+ CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
uh = rb_const_get(rb_cVM, usage_hash);
if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
@@ -507,11 +503,11 @@ vm_analysis_operand(int insn, int n, VALUE op)
void
vm_analysis_register(int reg, int isset)
{
- static ID usage_hash;
+ ID usage_hash;
VALUE uh;
VALUE rhash;
VALUE valstr;
- char *regstrs[] = {
+ static const char regstrs[][5] = {
"pc", /* 0 */
"sp", /* 1 */
"cfp", /* 2 */
@@ -520,7 +516,7 @@ vm_analysis_register(int reg, int isset)
"self", /* 5 */
"iseq", /* 6 */
};
- char *getsetstr[] = {
+ static const char getsetstr[][4] = {
"get",
"set",
};
@@ -528,12 +524,11 @@ vm_analysis_register(int reg, int isset)
VALUE cv;
- if (usage_hash == 0) {
+ CONST_ID(usage_hash, "USAGE_ANALYSIS_REGS");
+ if (syms[0] == 0) {
char buff[0x10];
int i;
- usage_hash = rb_intern("USAGE_ANALYSIS_REGS");
-
for (i = 0; i < sizeof(regstrs) / sizeof(regstrs[0]); i++) {
int j;
for (j = 0; j < 2; j++) {
diff --git a/vm_method.c b/vm_method.c
index d7160fc..ec9634f 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1105,6 +1105,8 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj)
void
Init_eval_method(void)
{
+#undef rb_intern
+
rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
basic_respond_to = rb_method_node(rb_cObject, idRespond_to);
rb_register_mark_object((VALUE)basic_respond_to);