[前][次][番号順一覧][スレッド一覧]

ruby-changes:24538

From: nobu <ko1@a...>
Date: Thu, 2 Aug 2012 07:31:05 +0900 (JST)
Subject: [ruby-changes:24538] nobu:r36589 (trunk): RB_TYPE_P BUILTIN_TYPE

nobu	2012-08-02 07:29:26 +0900 (Thu, 02 Aug 2012)

  New Revision: 36589

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36589

  Log:
    RB_TYPE_P BUILTIN_TYPE
    
    * string.c, vm_insnhelper.c, vm_method.c: use RB_TYPE_P() and
      BUILTIN_TYPE() if possible.

  Modified files:
    trunk/string.c
    trunk/vm_insnhelper.c
    trunk/vm_method.c

Index: string.c
===================================================================
--- string.c	(revision 36588)
+++ string.c	(revision 36589)
@@ -2539,7 +2539,8 @@
 	}
     }
 
-    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 @@
 	pos = rb_str_sublen(str, pos);
 	break;
 
+      generic:
       default: {
 	VALUE tmp;
 
@@ -2653,7 +2655,8 @@
 	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 @@
 	if (pos >= 0) return LONG2NUM(pos);
 	break;
 
+      generic:
       default: {
 	VALUE tmp;
 
@@ -2702,13 +2706,15 @@
 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 @@
 {
     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 @@
 	    return rb_str_dup(indx);
 	return Qnil;
 
+      generic:
       default:
 	/* check if indx is Range */
 	{
@@ -3440,13 +3449,15 @@
 {
     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_splice(str, beg, str_strlen(indx, 0), val);
 	return val;
 
+      generic:
       default:
 	/* check if indx is Range */
 	{
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 36588)
+++ vm_method.c	(revision 36589)
@@ -653,9 +653,7 @@
 	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 = "";
 	    }
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 36588)
+++ vm_insnhelper.c	(revision 36589)
@@ -1175,11 +1175,7 @@
 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));

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]