RB_TYPE_P BUILTIN_TYPE
* string.c, vm_insnhelper.c, vm_method.c: use RB_TYPE_P() and BUILTIN_TYPE() if possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
61b624d149
commit
d28d075cc1
26
string.c
26
string.c
@ -2539,7 +2539,8 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (TYPE(sub)) {
|
if (SPECIAL_CONST_P(sub)) goto generic;
|
||||||
|
switch (BUILTIN_TYPE(sub)) {
|
||||||
case T_REGEXP:
|
case T_REGEXP:
|
||||||
if (pos > str_strlen(str, STR_ENC_GET(str)))
|
if (pos > str_strlen(str, STR_ENC_GET(str)))
|
||||||
return Qnil;
|
return Qnil;
|
||||||
@ -2550,6 +2551,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
|
|||||||
pos = rb_str_sublen(str, pos);
|
pos = rb_str_sublen(str, pos);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
generic:
|
||||||
default: {
|
default: {
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
@ -2653,7 +2655,8 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
|||||||
pos = len;
|
pos = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (TYPE(sub)) {
|
if (SPECIAL_CONST_P(sub)) goto generic;
|
||||||
|
switch (BUILTIN_TYPE(sub)) {
|
||||||
case T_REGEXP:
|
case T_REGEXP:
|
||||||
/* enc = rb_get_check(str, sub); */
|
/* enc = rb_get_check(str, sub); */
|
||||||
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
|
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
|
||||||
@ -2666,6 +2669,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
|||||||
if (pos >= 0) return LONG2NUM(pos);
|
if (pos >= 0) return LONG2NUM(pos);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
generic:
|
||||||
default: {
|
default: {
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
@ -2702,13 +2706,15 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_str_match(VALUE x, VALUE y)
|
rb_str_match(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
switch (TYPE(y)) {
|
if (SPECIAL_CONST_P(y)) goto generic;
|
||||||
|
switch (BUILTIN_TYPE(y)) {
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
rb_raise(rb_eTypeError, "type mismatch: String given");
|
rb_raise(rb_eTypeError, "type mismatch: String given");
|
||||||
|
|
||||||
case T_REGEXP:
|
case T_REGEXP:
|
||||||
return rb_reg_match(y, x);
|
return rb_reg_match(y, x);
|
||||||
|
|
||||||
|
generic:
|
||||||
default:
|
default:
|
||||||
return rb_funcall(y, rb_intern("=~"), 1, x);
|
return rb_funcall(y, rb_intern("=~"), 1, x);
|
||||||
}
|
}
|
||||||
@ -3163,15 +3169,17 @@ rb_str_aref(VALUE str, VALUE indx)
|
|||||||
{
|
{
|
||||||
long idx;
|
long idx;
|
||||||
|
|
||||||
switch (TYPE(indx)) {
|
if (FIXNUM_P(indx)) {
|
||||||
case T_FIXNUM:
|
|
||||||
idx = FIX2LONG(indx);
|
idx = FIX2LONG(indx);
|
||||||
|
|
||||||
num_index:
|
num_index:
|
||||||
str = rb_str_substr(str, idx, 1);
|
str = rb_str_substr(str, idx, 1);
|
||||||
if (!NIL_P(str) && RSTRING_LEN(str) == 0) return Qnil;
|
if (!NIL_P(str) && RSTRING_LEN(str) == 0) return Qnil;
|
||||||
return str;
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SPECIAL_CONST_P(indx)) goto generic;
|
||||||
|
switch (BUILTIN_TYPE(indx)) {
|
||||||
case T_REGEXP:
|
case T_REGEXP:
|
||||||
return rb_str_subpat(str, indx, INT2FIX(0));
|
return rb_str_subpat(str, indx, INT2FIX(0));
|
||||||
|
|
||||||
@ -3180,6 +3188,7 @@ rb_str_aref(VALUE str, VALUE indx)
|
|||||||
return rb_str_dup(indx);
|
return rb_str_dup(indx);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
|
generic:
|
||||||
default:
|
default:
|
||||||
/* check if indx is Range */
|
/* check if indx is Range */
|
||||||
{
|
{
|
||||||
@ -3440,13 +3449,15 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
|
|||||||
{
|
{
|
||||||
long idx, beg;
|
long idx, beg;
|
||||||
|
|
||||||
switch (TYPE(indx)) {
|
if (FIXNUM_P(indx)) {
|
||||||
case T_FIXNUM:
|
|
||||||
idx = FIX2LONG(indx);
|
idx = FIX2LONG(indx);
|
||||||
num_index:
|
num_index:
|
||||||
rb_str_splice(str, idx, 1, val);
|
rb_str_splice(str, idx, 1, val);
|
||||||
return val;
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SPECIAL_CONST_P(indx)) goto generic;
|
||||||
|
switch (TYPE(indx)) {
|
||||||
case T_REGEXP:
|
case T_REGEXP:
|
||||||
rb_str_subpat_set(str, indx, INT2FIX(0), val);
|
rb_str_subpat_set(str, indx, INT2FIX(0), val);
|
||||||
return val;
|
return val;
|
||||||
@ -3460,6 +3471,7 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
|
|||||||
rb_str_splice(str, beg, str_strlen(indx, 0), val);
|
rb_str_splice(str, beg, str_strlen(indx, 0), val);
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
|
generic:
|
||||||
default:
|
default:
|
||||||
/* check if indx is Range */
|
/* check if indx is Range */
|
||||||
{
|
{
|
||||||
|
@ -1175,11 +1175,7 @@ static inline void
|
|||||||
vm_check_if_namespace(VALUE klass)
|
vm_check_if_namespace(VALUE klass)
|
||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str;
|
||||||
switch (TYPE(klass)) {
|
if (!RB_TYPE_P(klass, T_CLASS) && !RB_TYPE_P(klass, T_MODULE)) {
|
||||||
case T_CLASS:
|
|
||||||
case T_MODULE:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
str = rb_inspect(klass);
|
str = rb_inspect(klass);
|
||||||
rb_raise(rb_eTypeError, "%s is not a class/module",
|
rb_raise(rb_eTypeError, "%s is not a class/module",
|
||||||
StringValuePtr(str));
|
StringValuePtr(str));
|
||||||
|
@ -653,9 +653,7 @@ rb_undef(VALUE klass, ID id)
|
|||||||
if (FL_TEST(c, FL_SINGLETON)) {
|
if (FL_TEST(c, FL_SINGLETON)) {
|
||||||
VALUE obj = rb_ivar_get(klass, attached);
|
VALUE obj = rb_ivar_get(klass, attached);
|
||||||
|
|
||||||
switch (TYPE(obj)) {
|
if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {
|
||||||
case T_MODULE:
|
|
||||||
case T_CLASS:
|
|
||||||
c = obj;
|
c = obj;
|
||||||
s0 = "";
|
s0 = "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user