diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2020-05-12 02:12:06 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2020-05-12 02:14:27 +0900 |
commit | 42abad2464a78e3ec8a42f85c7bc878233f3ce16 (patch) | |
tree | c1aa0dbc813463918e39bf16395c815630ee4b75 /numeric.c | |
parent | 95ac235537fc0e46e4c18f1e82cf14d0a98b3b92 (diff) |
numeric.c: optimize `float ** 2` case by fastpath
It would be a relatively frequent case. It is still slower than
`float * float` because `*` has a dedicated VM instruction (opt_mult),
though.
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -1309,7 +1309,11 @@ VALUE rb_float_pow(VALUE x, VALUE y) { double dx, dy; - if (RB_TYPE_P(y, T_FIXNUM)) { + if (y == INT2FIX(2)) { + dx = RFLOAT_VALUE(x); + return DBL2NUM(dx * dx); + } + else if (RB_TYPE_P(y, T_FIXNUM)) { dx = RFLOAT_VALUE(x); dy = (double)FIX2LONG(y); } |