summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-10 06:30:23 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-10 06:30:23 +0000
commit9aa75d08ceb497645940f06bf690f3bdb764031e (patch)
treea95fa0e28592c41090df0e1fcae5dca5c160216e
parent9ef6eefbd30c54931a1fb06712f370e1853188e7 (diff)
downloadruby-9aa75d08ceb497645940f06bf690f3bdb764031e.tar.gz
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--numeric.c33
2 files changed, 20 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index d1edd6d826..aed4d75b2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Jan 10 11:15:04 2013 Kenta Murata <mrkn@cookpad.com>
+
+ * 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@tenderlovemaking.com>
* probes.d: updating probes to be more symmetrical, adding
diff --git a/numeric.c b/numeric.c
index 52e2c366ea..ea926a62ee 100644
--- a/numeric.c
+++ b/numeric.c
@@ -211,25 +211,6 @@ num_coerce(VALUE x, VALUE y)
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)
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]");