1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

rational.c: optimize Rational#-@

* rational.c (nurat_negate): introduced to optimize Rational#-@.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2016-11-12 06:07:01 +00:00
parent d611a7c77b
commit 2e9357e7ea

View file

@ -637,6 +637,19 @@ nurat_denominator(VALUE self)
return dat->den;
}
/*
* call-seq:
* -rat -> rational
*
* Negates +rat+.
*/
static VALUE
nurat_negate(VALUE self)
{
get_dat1(self);
return f_rational_new2(CLASS_OF(self), rb_int_uminus(dat->num), dat->den);
}
#ifndef NDEBUG
#define f_imul f_imul_orig
#endif
@ -2591,6 +2604,7 @@ Init_Rational(void)
rb_define_method(rb_cRational, "numerator", nurat_numerator, 0);
rb_define_method(rb_cRational, "denominator", nurat_denominator, 0);
rb_define_method(rb_cRational, "-@", nurat_negate, 0);
rb_define_method(rb_cRational, "+", rb_rational_plus, 1);
rb_define_method(rb_cRational, "-", nurat_sub, 1);
rb_define_method(rb_cRational, "*", nurat_mul, 1);