1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2008-06-09 09:25:32 +00:00
parent 250dd07021
commit 5a647a3f5f
32 changed files with 141 additions and 85 deletions

View file

@ -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> Mon Jun 9 17:56:30 2008 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb (Set#delete_if): Call to_a. * lib/set.rb (Set#delete_if): Call to_a.

View file

@ -3400,6 +3400,8 @@ rb_ary_drop_while(VALUE ary)
void void
Init_Array(void) Init_Array(void)
{ {
#undef rb_intern
rb_cArray = rb_define_class("Array", rb_cObject); rb_cArray = rb_define_class("Array", rb_cObject);
rb_include_module(rb_cArray, rb_mEnumerable); rb_include_module(rb_cArray, rb_mEnumerable);

View file

@ -129,9 +129,11 @@ build_Integer_times_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
end end
} }
*/ */
ID _self = rb_intern("#_self"); ID _self;
CONST_ID(_self, "#_self");
if (iseq->argc == 0) { 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(e));
rb_ary_push(param_vars, ID2SYM(_self)); rb_ary_push(param_vars, ID2SYM(_self));
iseq->argc += 2; iseq->argc += 2;
@ -145,10 +147,11 @@ build_Integer_times_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
Qundef); Qundef);
} }
else { else {
ID _e = rb_intern("#_e"); ID _e;
ID e = SYM2ID(rb_ary_entry(param_vars, 0)); ID e = SYM2ID(rb_ary_entry(param_vars, 0));
NODE *assign; NODE *assign;
CONST_ID(_e, "#_e");
rb_ary_push(param_vars, ID2SYM(_self)); rb_ary_push(param_vars, ID2SYM(_self));
rb_ary_push(local_vars, ID2SYM(_e)); rb_ary_push(local_vars, ID2SYM(_e));
iseq->argc++; iseq->argc++;
@ -230,9 +233,11 @@ build_Range_each_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
end end
} }
*/ */
ID _last = rb_intern("#_last"); ID _last;
CONST_ID(_last, "#_last");
if (iseq->argc == 0) { 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(e));
rb_ary_push(param_vars, ID2SYM(_last)); rb_ary_push(param_vars, ID2SYM(_last));
iseq->argc += 2; iseq->argc += 2;
@ -245,10 +250,11 @@ build_Range_each_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
Qundef); Qundef);
} }
else { else {
ID _e = rb_intern("#_e"); ID _e;
ID e = SYM2ID(rb_ary_entry(param_vars, 0)); ID e = SYM2ID(rb_ary_entry(param_vars, 0));
NODE *assign; NODE *assign;
CONST_ID(_e, "#_e");
rb_ary_push(param_vars, ID2SYM(_last)); rb_ary_push(param_vars, ID2SYM(_last));
rb_ary_push(local_vars, ID2SYM(_e)); rb_ary_push(local_vars, ID2SYM(_e));
iseq->argc++; iseq->argc++;
@ -362,11 +368,13 @@ build_Array_each_node(rb_iseq_t *iseq, NODE * node, NODE * lnode,
} }
*/ */
ID _self = rb_intern("#_self"); ID _self, _i;
ID _i = rb_intern("#_i");
CONST_ID(_self, "#_self");
CONST_ID(_i, "#_i");
if (iseq->argc == 0) { 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(_e));
rb_ary_push(param_vars, ID2SYM(_self)); rb_ary_push(param_vars, ID2SYM(_self));
iseq->argc += 2; iseq->argc += 2;

12
class.c
View file

@ -102,9 +102,9 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
ID id; ID id;
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig)); 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); 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); st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
} }
if (RCLASS_M_TBL(orig)) { if (RCLASS_M_TBL(orig)) {
@ -169,10 +169,12 @@ void
rb_singleton_class_attached(VALUE klass, VALUE obj) rb_singleton_class_attached(VALUE klass, VALUE obj)
{ {
if (FL_TEST(klass, FL_SINGLETON)) { if (FL_TEST(klass, FL_SINGLETON)) {
ID attached;
if (!RCLASS_IV_TBL(klass)) { if (!RCLASS_IV_TBL(klass)) {
RCLASS_IV_TBL(klass) = st_init_numtable(); 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 VALUE
rb_class_inherited(VALUE super, VALUE klass) rb_class_inherited(VALUE super, VALUE klass)
{ {
ID inherited;
if (!super) super = rb_cObject; 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 VALUE

View file

@ -198,6 +198,8 @@ cmp_between(VALUE x, VALUE min, VALUE max)
void void
Init_Comparable(void) Init_Comparable(void)
{ {
#undef rb_intern
rb_mComparable = rb_define_module("Comparable"); rb_mComparable = rb_define_module("Comparable");
rb_define_method(rb_mComparable, "==", cmp_equal, 1); rb_define_method(rb_mComparable, "==", cmp_equal, 1);
rb_define_method(rb_mComparable, ">", cmp_gt, 1); rb_define_method(rb_mComparable, ">", cmp_gt, 1);

View file

@ -761,11 +761,9 @@ iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
static int static int
iseq_set_exception_local_table(rb_iseq_t *iseq) iseq_set_exception_local_table(rb_iseq_t *iseq)
{ {
static ID id_dollar_bang; ID id_dollar_bang;
if (!id_dollar_bang) { CONST_ID(id_dollar_bang, "#$!");
id_dollar_bang = rb_intern("#$!");
}
iseq->local_table = (ID *)ALLOC_N(ID *, 1); iseq->local_table = (ID *)ALLOC_N(ID *, 1);
iseq->local_table_size = 1; iseq->local_table_size = 1;
iseq->local_size = 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 */ /* only joke */
{ {
static ID goto_id; ID goto_id;
static ID label_id; ID label_id;
VALUE label; VALUE label;
VALUE label_sym; VALUE label_sym;
if (goto_id == 0) {
goto_id = rb_intern("__goto__"); CONST_ID(goto_id, "__goto__");
label_id = rb_intern("__label__"); CONST_ID(label_id, "__label__");
}
if (nd_type(node) == NODE_FCALL && if (nd_type(node) == NODE_FCALL &&
(mid == goto_id || mid == label_id)) { (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; break;
} }
case NODE_SCLASS:{ case NODE_SCLASS:{
ID singletonclass;
VALUE iseqval = VALUE iseqval =
NEW_ISEQVAL(node->nd_body, rb_str_new2("singletonclass"), NEW_ISEQVAL(node->nd_body, rb_str_new2("singletonclass"),
ISEQ_TYPE_CLASS); ISEQ_TYPE_CLASS);
COMPILE(ret, "sclass#recv", node->nd_recv); COMPILE(ret, "sclass#recv", node->nd_recv);
ADD_INSN (ret, nd_line(node), putnil); ADD_INSN (ret, nd_line(node), putnil);
CONST_ID(singletonclass, "singletonclass");
ADD_INSN3(ret, nd_line(node), defineclass, ADD_INSN3(ret, nd_line(node), defineclass,
ID2SYM(rb_intern("singletonclass")), iseqval, INT2FIX(1)); ID2SYM(singletonclass), iseqval, INT2FIX(1));
if (poped) { if (poped) {
ADD_INSN(ret, nd_line(node), pop); 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 static VALUE
get_exception_sym2type(VALUE sym) get_exception_sym2type(VALUE sym)
{ {
#undef rb_intern
static VALUE symRescue, symEnsure, symRetry; static VALUE symRescue, symEnsure, symRetry;
static VALUE symBreak, symRedo, symNext; static VALUE symBreak, symRedo, symNext;

View file

@ -1387,6 +1387,8 @@ numeric_conjugate(VALUE self)
void void
Init_Complex(void) Init_Complex(void)
{ {
#undef rb_intern
assert(fprintf(stderr, "assert() is now active\n")); assert(fprintf(stderr, "assert() is now active\n"));
id_Unify = rb_intern("Unify"); id_Unify = rb_intern("Unify");

View file

@ -533,9 +533,7 @@ enc_check_capable(VALUE x)
ID ID
rb_id_encoding(void) rb_id_encoding(void)
{ {
if (!id_encoding) { CONST_ID(id_encoding, "encoding");
id_encoding = rb_intern("encoding");
}
return id_encoding; return id_encoding;
} }
@ -1162,6 +1160,8 @@ rb_enc_aliases(VALUE klass)
void void
Init_Encoding(void) Init_Encoding(void)
{ {
#undef rb_intern
id_base_encoding = rb_intern("#base_encoding"); id_base_encoding = rb_intern("#base_encoding");
rb_cEncoding = rb_define_class("Encoding", rb_cObject); rb_cEncoding = rb_define_class("Encoding", rb_cObject);

4
enum.c
View file

@ -1566,7 +1566,7 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
} }
} }
if (!allary) { if (!allary) {
conv = rb_intern("to_enum"); CONST_ID(conv, "to_enum");
for (i=0; i<argc; i++) { for (i=0; i<argc; i++) {
argv[i] = rb_funcall(argv[i], conv, 1, ID2SYM(id_each)); argv[i] = rb_funcall(argv[i], conv, 1, ID2SYM(id_each));
} }
@ -1800,6 +1800,8 @@ enum_cycle(int argc, VALUE *argv, VALUE obj)
void void
Init_Enumerable(void) Init_Enumerable(void)
{ {
#undef rb_intern
rb_mEnumerable = rb_define_module("Enumerable"); rb_mEnumerable = rb_define_module("Enumerable");
rb_define_method(rb_mEnumerable, "to_a", enum_to_a, -1); rb_define_method(rb_mEnumerable, "to_a", enum_to_a, -1);

13
error.c
View file

@ -496,9 +496,9 @@ exc_inspect(VALUE exc)
static VALUE static VALUE
exc_backtrace(VALUE exc) 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); return rb_attr_get(exc, bt);
} }
@ -506,7 +506,7 @@ VALUE
rb_check_backtrace(VALUE bt) rb_check_backtrace(VALUE bt)
{ {
long i; 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)) { if (!NIL_P(bt)) {
int t = TYPE(bt); int t = TYPE(bt);
@ -552,11 +552,12 @@ exc_set_backtrace(VALUE exc, VALUE bt)
static VALUE static VALUE
exc_equal(VALUE exc, VALUE obj) exc_equal(VALUE exc, VALUE obj)
{ {
ID id_mesg = rb_intern("mesg"); ID id_mesg;
if (exc == obj) return Qtrue; if (exc == obj) return Qtrue;
if (rb_obj_class(exc) != rb_obj_class(obj)) if (rb_obj_class(exc) != rb_obj_class(obj))
return rb_equal(obj, exc); 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))) if (!rb_equal(rb_attr_get(exc, id_mesg), rb_attr_get(obj, id_mesg)))
return Qfalse; return Qfalse;
if (!rb_equal(exc_backtrace(exc), exc_backtrace(obj))) if (!rb_equal(exc_backtrace(exc), exc_backtrace(obj)))
@ -963,7 +964,9 @@ static VALUE
syserr_eqq(VALUE self, VALUE exc) syserr_eqq(VALUE self, VALUE exc)
{ {
VALUE num, e; 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_obj_is_kind_of(exc, rb_eSystemCallError)) {
if (!rb_respond_to(exc, en)) return Qfalse; if (!rb_respond_to(exc, en)) return Qfalse;

2
eval.c
View file

@ -507,7 +507,7 @@ rb_make_exception(int argc, VALUE *argv)
case 3: case 3:
n = 1; n = 1;
exception_call: exception_call:
exception = rb_intern("exception"); CONST_ID(exception, "exception");
if (!rb_respond_to(argv[0], exception)) { if (!rb_respond_to(argv[0], exception)) {
rb_raise(rb_eTypeError, "exception class/object expected"); rb_raise(rb_eTypeError, "exception class/object expected");
} }

7
file.c
View file

@ -102,15 +102,14 @@ static VALUE
rb_get_path_check(VALUE obj, int check) rb_get_path_check(VALUE obj, int check)
{ {
VALUE tmp; VALUE tmp;
static ID to_path; ID to_path;
if (check) rb_check_safe_obj(obj); if (check) rb_check_safe_obj(obj);
tmp = rb_check_string_type(obj); tmp = rb_check_string_type(obj);
if (!NIL_P(tmp)) goto exit; 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)) { if (rb_respond_to(obj, to_path)) {
tmp = rb_funcall(obj, to_path, 0, 0); tmp = rb_funcall(obj, to_path, 0, 0);
} }

2
hash.c
View file

@ -2564,6 +2564,8 @@ env_update(VALUE env, VALUE hash)
void void
Init_Hash(void) Init_Hash(void)
{ {
#undef rb_intern
id_hash = rb_intern("hash"); id_hash = rb_intern("hash");
id_yield = rb_intern("yield"); id_yield = rb_intern("yield");
id_default = rb_intern("default"); id_default = rb_intern("default");

2
id.c
View file

@ -18,6 +18,8 @@
void void
Init_id(void) Init_id(void)
{ {
#undef rb_intern
/* Symbols */ /* Symbols */
symIFUNC = ID2SYM(rb_intern("<IFUNC>")); symIFUNC = ID2SYM(rb_intern("<IFUNC>"));
symCFUNC = ID2SYM(rb_intern("<CFUNC>")); symCFUNC = ID2SYM(rb_intern("<CFUNC>"));

View file

@ -764,17 +764,21 @@ const char *rb_id2name(ID);
ID rb_to_id(VALUE); ID rb_to_id(VALUE);
VALUE rb_id2str(ID); 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__ #ifdef __GNUC__
/* __builtin_constant_p and statement expression is available /* __builtin_constant_p and statement expression is available
* since gcc-2.7.2.3 at least. */ * since gcc-2.7.2.3 at least. */
#define rb_intern(str) \ #define rb_intern(str) \
(__builtin_constant_p(str) ? \ (__builtin_constant_p(str) ? \
({ \ CONST_ID_CACHE(/**/, str) : \
static ID rb_intern_id_cache; \
if (!rb_intern_id_cache) \
rb_intern_id_cache = rb_intern(str); \
rb_intern_id_cache; \
}) : \
rb_intern(str)) rb_intern(str))
#endif #endif

10
io.c
View file

@ -4231,7 +4231,7 @@ rb_f_open(int argc, VALUE *argv)
int redirect = Qfalse; int redirect = Qfalse;
if (argc >= 1) { if (argc >= 1) {
to_open = rb_intern("to_open"); CONST_ID(to_open, "to_open");
if (rb_respond_to(argv[0], to_open)) { if (rb_respond_to(argv[0], to_open)) {
redirect = Qtrue; redirect = Qtrue;
} }
@ -6178,11 +6178,11 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
if (!encoding) { if (!encoding) {
ID id; ID id;
id = rb_intern("encoding"); CONST_ID(id, "encoding");
encoding = ID2SYM(id); encoding = ID2SYM(id);
id = rb_intern("mode"); CONST_ID(id, "mode");
mode = ID2SYM(id); mode = ID2SYM(id);
id = rb_intern("open_args"); CONST_ID(id, "open_args");
open_args = ID2SYM(id); open_args = ID2SYM(id);
} }
v = rb_hash_aref(opt, open_args); v = rb_hash_aref(opt, open_args);
@ -7484,6 +7484,8 @@ rb_get_argv(void)
void void
Init_IO(void) Init_IO(void)
{ {
#undef rb_intern
VALUE rb_cARGF; VALUE rb_cARGF;
#ifdef __CYGWIN__ #ifdef __CYGWIN__
#include <sys/cygwin.h> #include <sys/cygwin.h>

12
iseq.c
View file

@ -956,12 +956,12 @@ exception_type2symbol(VALUE type)
{ {
ID id; ID id;
switch(type) { switch(type) {
case CATCH_TYPE_RESCUE: id = rb_intern("rescue"); break; case CATCH_TYPE_RESCUE: CONST_ID(id, "rescue"); break;
case CATCH_TYPE_ENSURE: id = rb_intern("ensure"); break; case CATCH_TYPE_ENSURE: CONST_ID(id, "ensure"); break;
case CATCH_TYPE_RETRY: id = rb_intern("retry"); break; case CATCH_TYPE_RETRY: CONST_ID(id, "retry"); break;
case CATCH_TYPE_BREAK: id = rb_intern("break"); break; case CATCH_TYPE_BREAK: CONST_ID(id, "break"); break;
case CATCH_TYPE_REDO: id = rb_intern("redo"); break; case CATCH_TYPE_REDO: CONST_ID(id, "redo"); break;
case CATCH_TYPE_NEXT: id = rb_intern("next"); break; case CATCH_TYPE_NEXT: CONST_ID(id, "next"); break;
default: default:
rb_bug("..."); rb_bug("...");
} }

View file

@ -1669,6 +1669,8 @@ marshal_load(int argc, VALUE *argv)
void void
Init_marshal(void) Init_marshal(void)
{ {
#undef rb_intern
VALUE rb_mMarshal = rb_define_module("Marshal"); VALUE rb_mMarshal = rb_define_module("Marshal");
s_dump = rb_intern("_dump"); s_dump = rb_intern("_dump");

View file

@ -3092,6 +3092,8 @@ fix_even_p(VALUE num)
void void
Init_Numeric(void) Init_Numeric(void)
{ {
#undef rb_intern
#if defined(__FreeBSD__) && __FreeBSD__ < 4 #if defined(__FreeBSD__) && __FreeBSD__ < 4
/* allow divide by zero -- Inf */ /* allow divide by zero -- Inf */
fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV|FP_X_OFL)); fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV|FP_X_OFL));

View file

@ -2365,6 +2365,8 @@ boot_defclass(const char *name, VALUE super)
void void
Init_Object(void) Init_Object(void)
{ {
#undef rb_intern
VALUE metaclass; VALUE metaclass;
rb_cBasicObject = boot_defclass("BasicObject", 0); rb_cBasicObject = boot_defclass("BasicObject", 0);

View file

@ -7761,9 +7761,9 @@ assignable_gen(struct parser_params *parser, ID id, NODE *val)
static void static void
shadowing_lvar_gen(struct parser_params *parser, ID name) 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 (uscore == name) return;
if (dyna_in_block()) { if (dyna_in_block()) {
if (dvar_curr(name)) { if (dvar_curr(name)) {

2
prec.c
View file

@ -124,6 +124,8 @@ prec_included(VALUE module, VALUE include)
void void
Init_Precision(void) Init_Precision(void)
{ {
#undef rb_intern
rb_mPrecision = rb_define_module("Precision"); rb_mPrecision = rb_define_module("Precision");
rb_define_singleton_method(rb_mPrecision, "included", prec_included, 1); rb_define_singleton_method(rb_mPrecision, "included", prec_included, 1);
rb_define_method(rb_mPrecision, "prec", prec_prec, 1); rb_define_method(rb_mPrecision, "prec", prec_prec, 1);

View file

@ -896,6 +896,8 @@ range_alloc(VALUE klass)
void void
Init_Range(void) Init_Range(void)
{ {
#undef rb_intern
id_cmp = rb_intern("<=>"); id_cmp = rb_intern("<=>");
id_succ = rb_intern("succ"); id_succ = rb_intern("succ");
id_beg = rb_intern("begin"); id_beg = rb_intern("begin");

View file

@ -1501,6 +1501,8 @@ nurat_s_induced_from(VALUE klass, VALUE n)
void void
Init_Rational(void) Init_Rational(void)
{ {
#undef rb_intern
assert(fprintf(stderr, "assert() is now active\n")); assert(fprintf(stderr, "assert() is now active\n"));
id_Unify = rb_intern("Unify"); id_Unify = rb_intern("Unify");

3
ruby.c
View file

@ -452,9 +452,10 @@ static void
require_libraries(struct cmdline_options *opt) require_libraries(struct cmdline_options *opt)
{ {
VALUE list = opt->req_list; VALUE list = opt->req_list;
ID require = rb_intern("require"); ID require;
Init_ext(); /* should be called here for some reason :-( */ Init_ext(); /* should be called here for some reason :-( */
CONST_ID(require, "require");
while (list && RARRAY_LEN(list) > 0) { while (list && RARRAY_LEN(list) > 0) {
VALUE feature = rb_ary_shift(list); VALUE feature = rb_ary_shift(list);
rb_funcall2(rb_vm_top_self(), require, 1, &feature); rb_funcall2(rb_vm_top_self(), require, 1, &feature);

View file

@ -2632,7 +2632,7 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg)
rb_scan_args(argc, argv, "11", &end, &exclusive); rb_scan_args(argc, argv, "11", &end, &exclusive);
excl = RTEST(exclusive); excl = RTEST(exclusive);
succ = rb_intern("succ"); CONST_ID(succ, "succ");
StringValue(end); StringValue(end);
enc = rb_enc_check(beg, end); enc = rb_enc_check(beg, end);
if (RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1 && if (RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1 &&
@ -6526,6 +6526,8 @@ rb_to_id(VALUE name)
void void
Init_String(void) Init_String(void)
{ {
#undef rb_intern
rb_cString = rb_define_class("String", rb_cObject); rb_cString = rb_define_class("String", rb_cObject);
rb_include_module(rb_cString, rb_mComparable); rb_include_module(rb_cString, rb_mComparable);
rb_define_alloc_func(rb_cString, str_alloc); rb_define_alloc_func(rb_cString, str_alloc);

View file

@ -3167,6 +3167,8 @@ ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always)
void void
Init_Thread(void) Init_Thread(void)
{ {
#undef rb_intern
VALUE cThGroup; VALUE cThGroup;
rb_define_singleton_method(rb_cThread, "new", thread_s_new, -1); rb_define_singleton_method(rb_cThread, "new", thread_s_new, -1);

2
time.c
View file

@ -2338,6 +2338,8 @@ time_load(VALUE klass, VALUE str)
void void
Init_Time(void) Init_Time(void)
{ {
#undef rb_intern
id_divmod = rb_intern("divmod"); id_divmod = rb_intern("divmod");
id_mul = rb_intern("*"); id_mul = rb_intern("*");
id_submicro = rb_intern("submicro"); id_submicro = rb_intern("submicro");

View file

@ -26,9 +26,9 @@ Init_var_tables(void)
{ {
rb_global_tbl = st_init_numtable(); rb_global_tbl = st_init_numtable();
rb_class_tbl = st_init_numtable(); rb_class_tbl = st_init_numtable();
autoload = rb_intern("__autoload__"); CONST_ID(autoload, "__autoload__");
classpath = rb_intern("__classpath__"); CONST_ID(classpath, "__classpath__");
tmp_classpath = rb_intern("__tmp_classpath__"); CONST_ID(tmp_classpath, "__tmp_classpath__");
} }
struct fc_result { struct fc_result {
@ -142,7 +142,9 @@ classname(VALUE klass)
if (!klass) klass = rb_cObject; if (!klass) klass = rb_cObject;
if (RCLASS_IV_TBL(klass)) { if (RCLASS_IV_TBL(klass)) {
if (!st_lookup(RCLASS_IV_TBL(klass), classpath, &path)) { 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)) { if (!st_lookup(RCLASS_IV_TBL(klass), classid, &path)) {
return find_class_path(klass); return find_class_path(klass);

14
vm.c
View file

@ -754,22 +754,22 @@ make_localjump_error(const char *mesg, VALUE value, int reason)
switch (reason) { switch (reason) {
case TAG_BREAK: case TAG_BREAK:
id = rb_intern("break"); CONST_ID(id, "break");
break; break;
case TAG_REDO: case TAG_REDO:
id = rb_intern("redo"); CONST_ID(id, "redo");
break; break;
case TAG_RETRY: case TAG_RETRY:
id = rb_intern("retry"); CONST_ID(id, "retry");
break; break;
case TAG_NEXT: case TAG_NEXT:
id = rb_intern("next"); CONST_ID(id, "next");
break; break;
case TAG_RETURN: case TAG_RETURN:
id = rb_intern("return"); CONST_ID(id, "return");
break; break;
default: default:
id = rb_intern("noreason"); CONST_ID(id, "noreason");
break; break;
} }
rb_iv_set(exc, "@exit_value", value); rb_iv_set(exc, "@exit_value", value);
@ -1241,7 +1241,7 @@ rb_thread_method_id_and_class(rb_thread_t *th,
} }
while (iseq) { while (iseq) {
if (RUBY_VM_IFUNC_P(iseq)) { if (RUBY_VM_IFUNC_P(iseq)) {
if (idp) *idp = rb_intern("<ifunc>"); if (idp) CONST_ID(*idp, "<ifunc>");
if (klassp) *klassp = 0; if (klassp) *klassp = 0;
return 1; return 1;
} }

View file

@ -425,18 +425,16 @@ debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp
void void
vm_analysis_insn(int insn) vm_analysis_insn(int insn)
{ {
static ID usage_hash; ID usage_hash;
static ID bigram_hash; ID bigram_hash;
static int prev_insn = -1; static int prev_insn = -1;
VALUE uh; VALUE uh;
VALUE ihash; VALUE ihash;
VALUE cv; VALUE cv;
if (usage_hash == 0) { CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
usage_hash = rb_intern("USAGE_ANALYSIS_INSN"); CONST_ID(bigram_hash, "USAGE_ANALYSIS_INSN_BIGRAM");
bigram_hash = rb_intern("USAGE_ANALYSIS_INSN_BIGRAM");
}
uh = rb_const_get(rb_cVM, usage_hash); uh = rb_const_get(rb_cVM, usage_hash);
if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) { if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
ihash = rb_hash_new(); ihash = rb_hash_new();
@ -473,7 +471,7 @@ extern VALUE insn_operand_intern(int insn, int op_no, VALUE op,
void void
vm_analysis_operand(int insn, int n, VALUE op) vm_analysis_operand(int insn, int n, VALUE op)
{ {
static ID usage_hash; ID usage_hash;
VALUE uh; VALUE uh;
VALUE ihash; VALUE ihash;
@ -481,9 +479,7 @@ vm_analysis_operand(int insn, int n, VALUE op)
VALUE valstr; VALUE valstr;
VALUE cv; VALUE cv;
if (usage_hash == 0) { CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
usage_hash = rb_intern("USAGE_ANALYSIS_INSN");
}
uh = rb_const_get(rb_cVM, usage_hash); uh = rb_const_get(rb_cVM, usage_hash);
if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) { if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
@ -507,11 +503,11 @@ vm_analysis_operand(int insn, int n, VALUE op)
void void
vm_analysis_register(int reg, int isset) vm_analysis_register(int reg, int isset)
{ {
static ID usage_hash; ID usage_hash;
VALUE uh; VALUE uh;
VALUE rhash; VALUE rhash;
VALUE valstr; VALUE valstr;
char *regstrs[] = { static const char regstrs[][5] = {
"pc", /* 0 */ "pc", /* 0 */
"sp", /* 1 */ "sp", /* 1 */
"cfp", /* 2 */ "cfp", /* 2 */
@ -520,7 +516,7 @@ vm_analysis_register(int reg, int isset)
"self", /* 5 */ "self", /* 5 */
"iseq", /* 6 */ "iseq", /* 6 */
}; };
char *getsetstr[] = { static const char getsetstr[][4] = {
"get", "get",
"set", "set",
}; };
@ -528,12 +524,11 @@ vm_analysis_register(int reg, int isset)
VALUE cv; VALUE cv;
if (usage_hash == 0) { CONST_ID(usage_hash, "USAGE_ANALYSIS_REGS");
if (syms[0] == 0) {
char buff[0x10]; char buff[0x10];
int i; int i;
usage_hash = rb_intern("USAGE_ANALYSIS_REGS");
for (i = 0; i < sizeof(regstrs) / sizeof(regstrs[0]); i++) { for (i = 0; i < sizeof(regstrs) / sizeof(regstrs[0]); i++) {
int j; int j;
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {

View file

@ -1105,6 +1105,8 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj)
void void
Init_eval_method(void) Init_eval_method(void)
{ {
#undef rb_intern
rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
basic_respond_to = rb_method_node(rb_cObject, idRespond_to); basic_respond_to = rb_method_node(rb_cObject, idRespond_to);
rb_register_mark_object((VALUE)basic_respond_to); rb_register_mark_object((VALUE)basic_respond_to);