[前][次][番号順一覧][スレッド一覧]

ruby-changes:62051

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:08:26 +0900 (JST)
Subject: [ruby-changes:62051] bf19820bb3 (master): flo_to_s: do not goto into a branch

https://git.ruby-lang.org/ruby.git/commit/?id=bf19820bb3

From bf19820bb383cffd2b85cc0c2c6a6e72f5e5f471 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 16 Jun 2020 09:42:18 +0900
Subject: 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.

diff --git a/numeric.c b/numeric.c
index 4fee3d9..8843be9 100644
--- a/numeric.c
+++ b/numeric.c
@@ -985,18 +985,21 @@ flo_to_s(VALUE flt) https://github.com/ruby/ruby/blob/trunk/numeric.c#L985
 	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;
 }
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]