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

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:
nobu 2012-08-01 22:29:26 +00:00
parent 61b624d149
commit d28d075cc1
3 changed files with 21 additions and 15 deletions

View file

@ -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:
if (pos > str_strlen(str, STR_ENC_GET(str)))
return Qnil;
@ -2550,6 +2551,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
pos = rb_str_sublen(str, pos);
break;
generic:
default: {
VALUE tmp;
@ -2653,7 +2655,8 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
pos = len;
}
switch (TYPE(sub)) {
if (SPECIAL_CONST_P(sub)) goto generic;
switch (BUILTIN_TYPE(sub)) {
case T_REGEXP:
/* enc = rb_get_check(str, sub); */
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);
break;
generic:
default: {
VALUE tmp;
@ -2702,13 +2706,15 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
static VALUE
rb_str_match(VALUE x, VALUE y)
{
switch (TYPE(y)) {
if (SPECIAL_CONST_P(y)) goto generic;
switch (BUILTIN_TYPE(y)) {
case T_STRING:
rb_raise(rb_eTypeError, "type mismatch: String given");
case T_REGEXP:
return rb_reg_match(y, x);
generic:
default:
return rb_funcall(y, rb_intern("=~"), 1, x);
}
@ -3163,15 +3169,17 @@ rb_str_aref(VALUE str, VALUE indx)
{
long idx;
switch (TYPE(indx)) {
case T_FIXNUM:
if (FIXNUM_P(indx)) {
idx = FIX2LONG(indx);
num_index:
str = rb_str_substr(str, idx, 1);
if (!NIL_P(str) && RSTRING_LEN(str) == 0) return Qnil;
return str;
}
if (SPECIAL_CONST_P(indx)) goto generic;
switch (BUILTIN_TYPE(indx)) {
case T_REGEXP:
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 Qnil;
generic:
default:
/* check if indx is Range */
{
@ -3440,13 +3449,15 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
{
long idx, beg;
switch (TYPE(indx)) {
case T_FIXNUM:
if (FIXNUM_P(indx)) {
idx = FIX2LONG(indx);
num_index:
rb_str_splice(str, idx, 1, val);
return val;
}
if (SPECIAL_CONST_P(indx)) goto generic;
switch (TYPE(indx)) {
case T_REGEXP:
rb_str_subpat_set(str, indx, INT2FIX(0), 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);
return val;
generic:
default:
/* check if indx is Range */
{

View file

@ -1175,11 +1175,7 @@ static inline void
vm_check_if_namespace(VALUE klass)
{
VALUE str;
switch (TYPE(klass)) {
case T_CLASS:
case T_MODULE:
break;
default:
if (!RB_TYPE_P(klass, T_CLASS) && !RB_TYPE_P(klass, T_MODULE)) {
str = rb_inspect(klass);
rb_raise(rb_eTypeError, "%s is not a class/module",
StringValuePtr(str));

View file

@ -653,9 +653,7 @@ rb_undef(VALUE klass, ID id)
if (FL_TEST(c, FL_SINGLETON)) {
VALUE obj = rb_ivar_get(klass, attached);
switch (TYPE(obj)) {
case T_MODULE:
case T_CLASS:
if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {
c = obj;
s0 = "";
}