summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-16 09:42:18 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commitbf19820bb383cffd2b85cc0c2c6a6e72f5e5f471 (patch)
treed492617872bb3b4ad187691ad162a1e8242cc050 /numeric.c
parent41703fcfabee00320f67875d743f4bc002eb65c9 (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.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/numeric.c b/numeric.c
index 4fee3d9df9..8843be9e58 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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;
}