* array.c (ary_join_1): reduce overhead of TYPE().

* eval.c (rb_frozen_class_p, rb_mod_{append,prepend}_features): ditto.

* string.c (rb_to_id): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-04-04 08:23:10 +00:00
Родитель 5e2c39ed22
Коммит fd7dc1b6ea
3 изменённых файлов: 30 добавлений и 37 удалений

11
array.c
Просмотреть файл

@ -1839,13 +1839,12 @@ ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result, int *first)
rb_str_buf_append(result, sep);
val = RARRAY_PTR(ary)[i];
switch (TYPE(val)) {
case T_STRING:
if (RB_TYPE_P(val, T_STRING)) {
str_join:
rb_str_buf_append(result, val);
*first = FALSE;
break;
case T_ARRAY:
}
else if (RB_TYPE_P(val, T_ARRAY)) {
obj = val;
ary_join:
if (val == ary) {
@ -1860,8 +1859,8 @@ ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result, int *first)
args[3] = (VALUE)first;
rb_exec_recursive(recursive_join, obj, (VALUE)args);
}
break;
default:
}
else {
tmp = rb_check_string_type(val);
if (!NIL_P(tmp)) {
val = tmp;

30
eval.c
Просмотреть файл

@ -34,6 +34,10 @@ VALUE rb_eSysStackError;
#include "eval_error.c"
#include "eval_jump.c"
#define CLASS_OR_MODULE_P(obj) \
(!SPECIAL_CONST_P(obj) && \
(BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
/* Initializes the Ruby VM and builtin libraries.
* @retval 0 if succeeded.
* @retval non-zero an error occured.
@ -402,13 +406,17 @@ rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
void
rb_frozen_class_p(VALUE klass)
{
const char *desc = "something(?!)";
if (SPECIAL_CONST_P(klass)) {
noclass:
Check_Type(klass, T_CLASS);
}
if (OBJ_FROZEN(klass)) {
const char *desc;
if (FL_TEST(klass, FL_SINGLETON))
desc = "object";
else {
switch (TYPE(klass)) {
switch (BUILTIN_TYPE(klass)) {
case T_MODULE:
case T_ICLASS:
desc = "module";
@ -416,6 +424,8 @@ rb_frozen_class_p(VALUE klass)
case T_CLASS:
desc = "class";
break;
default:
goto noclass;
}
}
rb_error_frozen(desc);
@ -953,13 +963,8 @@ rb_frame_pop(void)
static VALUE
rb_mod_append_features(VALUE module, VALUE include)
{
switch (TYPE(include)) {
case T_CLASS:
case T_MODULE:
break;
default:
if (!CLASS_OR_MODULE_P(include)) {
Check_Type(include, T_CLASS);
break;
}
rb_include_module(include, module);
@ -1006,13 +1011,8 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
static VALUE
rb_mod_prepend_features(VALUE module, VALUE prepend)
{
switch (TYPE(prepend)) {
case T_CLASS:
case T_MODULE:
break;
default:
if (!CLASS_OR_MODULE_P(prepend)) {
Check_Type(prepend, T_CLASS);
break;
}
rb_prepend_module(prepend, module);

Просмотреть файл

@ -8152,24 +8152,18 @@ rb_to_id(VALUE name)
{
VALUE tmp;
switch (TYPE(name)) {
default:
tmp = rb_check_string_type(name);
if (NIL_P(tmp)) {
tmp = rb_inspect(name);
rb_raise(rb_eTypeError, "%s is not a symbol",
RSTRING_PTR(tmp));
}
name = tmp;
/* fall through */
case T_STRING:
name = rb_str_intern(name);
/* fall through */
case T_SYMBOL:
if (SYMBOL_P(name)) {
return SYM2ID(name);
}
UNREACHABLE;
if (!RB_TYPE_P(name, T_STRING)) {
tmp = rb_check_string_type(name);
if (NIL_P(tmp)) {
rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol",
name);
}
name = tmp;
}
return rb_intern_str(name);
}
/*