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

ruby-changes:62040

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

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

From 5f926b2b0013fc196ba627e70b7961a71aabca11 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: Thu, 18 Jun 2020 16:55:52 +0900
Subject: rb_str_partition: 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/string.c b/string.c
index c74e8eb..903222e 100644
--- a/string.c
+++ b/string.c
@@ -9939,8 +9939,7 @@ rb_str_partition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L9939
     if (RB_TYPE_P(sep, T_REGEXP)) {
 	pos = rb_reg_search(sep, str, 0, 0);
 	if (pos < 0) {
-	  failed:
-	    return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
+            goto failed;
 	}
 	sep = rb_str_subpat(str, sep, INT2FIX(0));
     }
@@ -9952,6 +9951,9 @@ rb_str_partition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L9951
 		          sep,
 		          rb_str_subseq(str, pos+RSTRING_LEN(sep),
 					     RSTRING_LEN(str)-pos-RSTRING_LEN(sep)));
+
+  failed:
+    return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
 }
 
 /*
-- 
cgit v0.10.2


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

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