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

ruby-changes:62029

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

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

From 6df790f22ed48c9998c12dc5eaccf9d13e545185 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: Wed, 17 Jun 2020 14:59:44 +0900
Subject: rb_enc_cr_str_buf_cat: 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 da07bd5..c9c65a4 100644
--- a/string.c
+++ b/string.c
@@ -2975,9 +2975,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, https://github.com/ruby/ruby/blob/trunk/string.c#L2975
         ptr_cr != ENC_CODERANGE_7BIT) {
 	str_enc = rb_enc_from_index(str_encindex);
 	ptr_enc = rb_enc_from_index(ptr_encindex);
-      incompatible:
-        rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
-		 rb_enc_name(str_enc), rb_enc_name(ptr_enc));
+        goto incompatible;
     }
 
     if (str_cr == ENC_CODERANGE_UNKNOWN) {
@@ -3013,6 +3011,10 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, https://github.com/ruby/ruby/blob/trunk/string.c#L3011
     str_buf_cat(str, ptr, len);
     ENCODING_CODERANGE_SET(str, res_encindex, res_cr);
     return str;
+
+  incompatible:
+    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
+             rb_enc_name(str_enc), rb_enc_name(ptr_enc));
 }
 
 VALUE
-- 
cgit v0.10.2


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

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