diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-16 09:42:18 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | bf19820bb383cffd2b85cc0c2c6a6e72f5e5f471 (patch) | |
tree | d492617872bb3b4ad187691ad162a1e8242cc050 /numeric.c | |
parent | 41703fcfabee00320f67875d743f4bc002eb65c9 (diff) |
flo_to_s: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea. Better refactor.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -985,18 +985,21 @@ flo_to_s(VALUE flt) memcpy(ptr -= decpt, buf, digs); } else { - exp: - if (digs > 1) { - memmove(buf + 2, buf + 1, digs - 1); - } - else { - buf[2] = '0'; - digs++; - } - buf[1] = '.'; - rb_str_cat(s, buf, digs + 1); - rb_str_catf(s, "e%+03d", decpt - 1); + goto exp; + } + return s; + + exp: + if (digs > 1) { + memmove(buf + 2, buf + 1, digs - 1); + } + else { + buf[2] = '0'; + digs++; } + buf[1] = '.'; + rb_str_cat(s, buf, digs + 1); + rb_str_catf(s, "e%+03d", decpt - 1); return s; } |