ruby-changes:12967
From: akr <ko1@a...>
Date: Sun, 30 Aug 2009 10:31:27 +0900 (JST)
Subject: [ruby-changes:12967] Ruby:r24709 (trunk): * time.c (eq): apply RTEST.
akr 2009-08-30 10:26:56 +0900 (Sun, 30 Aug 2009) New Revision: 24709 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24709 Log: * time.c (eq): apply RTEST. (ne): ditto. (add): avoid method dispatch for bignums. (sub): ditto. (mul): ditto. (mod): ditto. Modified files: trunk/ChangeLog trunk/time.c Index: time.c =================================================================== --- time.c (revision 24708) +++ time.c (revision 24709) @@ -106,17 +106,51 @@ static ID id_divmod, id_mul, id_submicro, id_subnano; static ID id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift; -#define eq(x,y) (rb_funcall((x), id_eq, 1, (y))) -#define ne(x,y) (rb_funcall((x), id_ne, 1, (y))) +#define eq(x,y) (RTEST(rb_funcall((x), id_eq, 1, (y)))) +#define ne(x,y) (RTEST(rb_funcall((x), id_ne, 1, (y)))) #define lt(x,y) (RTEST(rb_funcall((x), '<', 1, (y)))) #define gt(x,y) (RTEST(rb_funcall((x), '>', 1, (y)))) #define le(x,y) (!gt(x,y)) #define ge(x,y) (!lt(x,y)) -#define add(x,y) (rb_funcall((x), '+', 1, (y))) -#define sub(x,y) (rb_funcall((x), '-', 1, (y))) -#define mul(x,y) (rb_funcall((x), '*', 1, (y))) + +static VALUE +add(VALUE x, VALUE y) +{ + switch (TYPE(x)) { + case T_BIGNUM: return rb_big_plus(x, y); + default: return rb_funcall(x, '+', 1, y); + } +} + +static VALUE +sub(VALUE x, VALUE y) +{ + switch (TYPE(x)) { + case T_BIGNUM: return rb_big_minus(x, y); + default: return rb_funcall(x, '-', 1, y); + } +} + +static VALUE +mul(VALUE x, VALUE y) +{ + switch (TYPE(x)) { + case T_BIGNUM: return rb_big_mul(x, y); + default: return rb_funcall(x, '*', 1, y); + } +} + #define div(x,y) (rb_funcall((x), id_div, 1, (y))) -#define mod(x,y) (rb_funcall((x), '%', 1, (y))) + +static VALUE +mod(VALUE x, VALUE y) +{ + switch (TYPE(x)) { + case T_BIGNUM: return rb_big_modulo(x, y); + default: return rb_funcall(x, '%', 1, y); + } +} + #define neg(x) (sub(INT2FIX(0), (x))) #define cmp(x,y) (rb_funcall((x), id_cmp, 1, (y))) #define lshift(x,y) (rb_funcall((x), id_lshift, 1, (y))) Index: ChangeLog =================================================================== --- ChangeLog (revision 24708) +++ ChangeLog (revision 24709) @@ -1,3 +1,12 @@ +Sun Aug 30 10:24:43 2009 Tanaka Akira <akr@f...> + + * time.c (eq): apply RTEST. + (ne): ditto. + (add): avoid method dispatch for bignums. + (sub): ditto. + (mul): ditto. + (mod): ditto. + Sun Aug 30 09:45:11 2009 Tanaka Akira <akr@f...> * bignum.c (bigmul1_single): new function specialized respect to -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/