diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-09 02:06:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-09 02:06:39 +0000 |
commit | 40a1d28a5b17d0ffef6bc3879eaa5d9820a52604 (patch) | |
tree | 15d11151d427221b37bb076bc57fdc40f8736953 /complex.c | |
parent | 205fdf32acb19cc7b6a5cd25d2e8356f7b2091c2 (diff) | |
download | ruby-40a1d28a5b17d0ffef6bc3879eaa5d9820a52604.tar.gz |
complex.c: removed redundant conditions
Fixnums can be compared by object values themselves only.
Addition/subtraction/mulplication of fixnum 0 do not affect the
sign.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r-- | complex.c | 36 |
1 files changed, 9 insertions, 27 deletions
@@ -70,12 +70,10 @@ f_##n(VALUE x, VALUE y)\ inline static VALUE f_add(VALUE x, VALUE y) { -#ifndef PRESERVE_SIGNEDZERO - if (FIXNUM_P(y) && FIXNUM_ZERO_P(y)) + if (FIXNUM_ZERO_P(y)) return x; - else if (FIXNUM_P(x) && FIXNUM_ZERO_P(x)) + if (FIXNUM_ZERO_P(x)) return y; -#endif return rb_funcall(x, '+', 1, y); } @@ -107,36 +105,20 @@ f_gt_p(VALUE x, VALUE y) inline static VALUE f_mul(VALUE x, VALUE y) { -#ifndef PRESERVE_SIGNEDZERO - if (FIXNUM_P(y)) { - long iy = FIX2LONG(y); - if (iy == 0) { - if (RB_INTEGER_TYPE_P(x)) - return ZERO; - } - else if (iy == 1) - return x; - } - else if (FIXNUM_P(x)) { - long ix = FIX2LONG(x); - if (ix == 0) { - if (RB_INTEGER_TYPE_P(y)) - return ZERO; - } - else if (ix == 1) - return y; - } -#endif + if (FIXNUM_ZERO_P(y) && RB_INTEGER_TYPE_P(x)) + return ZERO; + if (FIXNUM_ZERO_P(x) && RB_INTEGER_TYPE_P(y)) + return ZERO; + if (y == ONE) return x; + if (x == ONE) return y; return rb_funcall(x, '*', 1, y); } inline static VALUE f_sub(VALUE x, VALUE y) { -#ifndef PRESERVE_SIGNEDZERO - if (FIXNUM_P(y) && FIXNUM_ZERO_P(y)) + if (FIXNUM_ZERO_P(y)) return x; -#endif return rb_funcall(x, '-', 1, y); } |