From ce357ef152869d3c5bfd2e088a31d879daa4ecb6 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 5 Mar 2013 01:18:55 +0000 Subject: [PATCH] numeric.c: optimize for Bignum * numeric.c (rb_int_succ, rb_int_pred): shortcut optimization for Bignum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ numeric.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 41bd7422ad..0515989cac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Mar 5 10:19:09 2013 Nobuyoshi Nakada + + * numeric.c (rb_int_succ, rb_int_pred): shortcut optimization for + Bignum. + Tue Mar 5 10:02:48 2013 Nobuyoshi Nakada * lib/rubygems/ext/ext_conf_builder.rb (Gem::Ext::ExtConfBuilder.build): diff --git a/numeric.c b/numeric.c index fe85d6cc31..342527c01d 100644 --- a/numeric.c +++ b/numeric.c @@ -2390,6 +2390,9 @@ int_succ(VALUE num) long i = FIX2LONG(num) + 1; return LONG2NUM(i); } + if (RB_TYPE_P(num, T_BIGNUM)) { + return rb_big_plus(num, INT2FIX(1)); + } return rb_funcall(num, '+', 1, INT2FIX(1)); } @@ -2410,6 +2413,9 @@ int_pred(VALUE num) long i = FIX2LONG(num) - 1; return LONG2NUM(i); } + if (RB_TYPE_P(num, T_BIGNUM)) { + return rb_big_minus(num, INT2FIX(1)); + } return rb_funcall(num, '-', 1, INT2FIX(1)); }