From dfd26e3a473aa76fce20dc1359b0c4ab1d88eea9 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 15 Feb 2014 02:48:44 +0000 Subject: [PATCH] * bignum.c (rb_big_cmp): Avoid bignum allocation for comparison between bignum and fixnum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ bignum.c | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index bfc446be6a..4881cec769 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Feb 15 11:47:47 2014 Tanaka Akira + + * bignum.c (rb_big_cmp): Avoid bignum allocation for comparison + between bignum and fixnum. + Sat Feb 15 10:55:12 2014 Hiroshi Shirosaki * ext/-test-/win32/fd_setsize/depend: fix wrong dependencies. diff --git a/bignum.c b/bignum.c index d2eb38e489..eb04e43814 100644 --- a/bignum.c +++ b/bignum.c @@ -5277,13 +5277,17 @@ rb_big_cmp(VALUE x, VALUE y) { int cmp; - if (y == INT2FIX(0)) { - if (BIGZEROP(x)) return INT2FIX(0); - if (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1); - return INT2FIX(1); - } - else if (FIXNUM_P(y)) { - y = rb_int2big(FIX2LONG(y)); + if (FIXNUM_P(y)) { + x = bignorm(x); + if (FIXNUM_P(x)) { + if (FIX2LONG(x) > FIX2LONG(y)) return INT2FIX(1); + if (FIX2LONG(x) < FIX2LONG(y)) return INT2FIX(-1); + return INT2FIX(0); + } + else { + if (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1); + return INT2FIX(1); + } } else if (RB_BIGNUM_TYPE_P(y)) { }