mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
reduce overhead of TYPE
* 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:
parent
5e2c39ed22
commit
fd7dc1b6ea
3 changed files with 30 additions and 37 deletions
11
array.c
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);
|
rb_str_buf_append(result, sep);
|
||||||
|
|
||||||
val = RARRAY_PTR(ary)[i];
|
val = RARRAY_PTR(ary)[i];
|
||||||
switch (TYPE(val)) {
|
if (RB_TYPE_P(val, T_STRING)) {
|
||||||
case T_STRING:
|
|
||||||
str_join:
|
str_join:
|
||||||
rb_str_buf_append(result, val);
|
rb_str_buf_append(result, val);
|
||||||
*first = FALSE;
|
*first = FALSE;
|
||||||
break;
|
}
|
||||||
case T_ARRAY:
|
else if (RB_TYPE_P(val, T_ARRAY)) {
|
||||||
obj = val;
|
obj = val;
|
||||||
ary_join:
|
ary_join:
|
||||||
if (val == ary) {
|
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;
|
args[3] = (VALUE)first;
|
||||||
rb_exec_recursive(recursive_join, obj, (VALUE)args);
|
rb_exec_recursive(recursive_join, obj, (VALUE)args);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
else {
|
||||||
tmp = rb_check_string_type(val);
|
tmp = rb_check_string_type(val);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
val = tmp;
|
val = tmp;
|
||||||
|
|
30
eval.c
30
eval.c
|
@ -34,6 +34,10 @@ VALUE rb_eSysStackError;
|
||||||
#include "eval_error.c"
|
#include "eval_error.c"
|
||||||
#include "eval_jump.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.
|
/* Initializes the Ruby VM and builtin libraries.
|
||||||
* @retval 0 if succeeded.
|
* @retval 0 if succeeded.
|
||||||
* @retval non-zero an error occured.
|
* @retval non-zero an error occured.
|
||||||
|
@ -402,13 +406,17 @@ rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
|
||||||
void
|
void
|
||||||
rb_frozen_class_p(VALUE klass)
|
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)) {
|
if (OBJ_FROZEN(klass)) {
|
||||||
|
const char *desc;
|
||||||
|
|
||||||
if (FL_TEST(klass, FL_SINGLETON))
|
if (FL_TEST(klass, FL_SINGLETON))
|
||||||
desc = "object";
|
desc = "object";
|
||||||
else {
|
else {
|
||||||
switch (TYPE(klass)) {
|
switch (BUILTIN_TYPE(klass)) {
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_ICLASS:
|
case T_ICLASS:
|
||||||
desc = "module";
|
desc = "module";
|
||||||
|
@ -416,6 +424,8 @@ rb_frozen_class_p(VALUE klass)
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
desc = "class";
|
desc = "class";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
goto noclass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_error_frozen(desc);
|
rb_error_frozen(desc);
|
||||||
|
@ -953,13 +963,8 @@ rb_frame_pop(void)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_mod_append_features(VALUE module, VALUE include)
|
rb_mod_append_features(VALUE module, VALUE include)
|
||||||
{
|
{
|
||||||
switch (TYPE(include)) {
|
if (!CLASS_OR_MODULE_P(include)) {
|
||||||
case T_CLASS:
|
|
||||||
case T_MODULE:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Check_Type(include, T_CLASS);
|
Check_Type(include, T_CLASS);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
rb_include_module(include, module);
|
rb_include_module(include, module);
|
||||||
|
|
||||||
|
@ -1006,13 +1011,8 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_mod_prepend_features(VALUE module, VALUE prepend)
|
rb_mod_prepend_features(VALUE module, VALUE prepend)
|
||||||
{
|
{
|
||||||
switch (TYPE(prepend)) {
|
if (!CLASS_OR_MODULE_P(prepend)) {
|
||||||
case T_CLASS:
|
|
||||||
case T_MODULE:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Check_Type(prepend, T_CLASS);
|
Check_Type(prepend, T_CLASS);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
rb_prepend_module(prepend, module);
|
rb_prepend_module(prepend, module);
|
||||||
|
|
||||||
|
|
26
string.c
26
string.c
|
@ -8152,24 +8152,18 @@ rb_to_id(VALUE name)
|
||||||
{
|
{
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
switch (TYPE(name)) {
|
if (SYMBOL_P(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:
|
|
||||||
return SYM2ID(name);
|
return SYM2ID(name);
|
||||||
}
|
}
|
||||||
|
if (!RB_TYPE_P(name, T_STRING)) {
|
||||||
UNREACHABLE;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue