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

ruby-changes:26705

From: mrkn <ko1@a...>
Date: Thu, 10 Jan 2013 15:30:32 +0900 (JST)
Subject: [ruby-changes:26705] mrkn:r38756 (trunk): * numeric.c (do_coerce): speed optimization by using rb_check_funcall

mrkn	2013-01-10 15:30:23 +0900 (Thu, 10 Jan 2013)

  New Revision: 38756

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

  Log:
    * numeric.c (do_coerce): speed optimization by using rb_check_funcall
      instead of rb_rescue + rb_funcall.
      This fix is based on the patch by Benoit Daloze.
      [Bug #7645] [ruby-core:51213]

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38755)
+++ ChangeLog	(revision 38756)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 10 11:15:04 2013  Kenta Murata  <mrkn@c...>
+
+	* numeric.c (do_coerce): speed optimization by using rb_check_funcall
+	  instead of rb_rescue + rb_funcall.
+	  This fix is based on the patch by Benoit Daloze.
+	  [Bug #7645] [ruby-core:51213]
+
 Thu Jan 10 11:15:04 2013  Aaron Patterson <aaron@t...>
 
 	* probes.d: updating probes to be more symmetrical, adding
Index: numeric.c
===================================================================
--- numeric.c	(revision 38755)
+++ numeric.c	(revision 38756)
@@ -211,25 +211,6 @@ num_coerce(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L211
     return rb_assoc_new(y, x);
 }
 
-static VALUE
-coerce_body(VALUE *x)
-{
-    return rb_funcall(x[1], id_coerce, 1, x[0]);
-}
-
-static VALUE
-coerce_rescue(VALUE *x)
-{
-    volatile VALUE v = rb_inspect(x[1]);
-
-    rb_raise(rb_eTypeError, "%s can't be coerced into %s",
-	     rb_special_const_p(x[1])?
-	     RSTRING_PTR(v):
-	     rb_obj_classname(x[1]),
-	     rb_obj_classname(x[0]));
-    return Qnil;		/* dummy */
-}
-
 static int
 do_coerce(VALUE *x, VALUE *y, int err)
 {
@@ -238,7 +219,19 @@ do_coerce(VALUE *x, VALUE *y, int err) https://github.com/ruby/ruby/blob/trunk/numeric.c#L219
 
     a[0] = *x; a[1] = *y;
 
-    ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a);
+    ary = rb_check_funcall(*y, id_coerce, 1, x);
+    if (ary == Qundef) {
+	if (err) {
+	    volatile VALUE v = rb_inspect(*y);
+	    rb_raise(rb_eTypeError, "%s can't be coerced into %s",
+		     rb_special_const_p(*y)?
+		     RSTRING_PTR(v):
+		     rb_obj_classname(*y),
+		     rb_obj_classname(*x));
+        }
+	return FALSE;	/* dummy */
+    }
+
     if (!RB_TYPE_P(ary, T_ARRAY) || RARRAY_LEN(ary) != 2) {
 	if (err) {
 	    rb_raise(rb_eTypeError, "coerce must return [x, y]");

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

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