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

ruby-changes:62071

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

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

From ad6512f359fe38d587715c618380e245af586be1 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: Fri, 19 Jun 2020 10:46:55 +0900
Subject: rb_enc_synmane_type: 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/symbol.c b/symbol.c
index 185c6a8..b40af88 100644
--- a/symbol.c
+++ b/symbol.c
@@ -316,7 +316,11 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int a https://github.com/ruby/ruby/blob/trunk/symbol.c#L316
 
       default:
 	type = rb_sym_constant_char_p(m, e-m, enc) ? ID_CONST : ID_LOCAL;
-      id:
+        goto id;
+    }
+    goto stophere;
+
+  id:
 	if (m >= e || (*m != '_' && !ISALPHA(*m) && ISASCII(*m))) {
 	    if (len > 1 && *(e-1) == '=') {
 		type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
@@ -325,7 +329,7 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int a https://github.com/ruby/ruby/blob/trunk/symbol.c#L329
 	    return -1;
 	}
 	while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
-	if (m >= e) break;
+        if (m >= e) goto stophere;
 	switch (*m) {
 	  case '!': case '?':
 	    if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1;
@@ -339,8 +343,8 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int a https://github.com/ruby/ruby/blob/trunk/symbol.c#L343
 	    ++m;
 	    break;
 	}
-	break;
-    }
+
+  stophere:
     return m == e ? type : -1;
 }
 
-- 
cgit v0.10.2


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

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