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

ruby-changes:62068

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

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

From 3d636eccfc8412423ee592a65f4e5aaf4308c683 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 14:14:02 +0900
Subject: make_econv_exception: 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/transcode.c b/transcode.c
index 1f533b6..fdc3514 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2047,7 +2047,6 @@ make_econv_exception(rb_econv_t *ec) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2047
         size_t readagain_len = ec->last_error.readagain_len;
         VALUE bytes2 = Qnil;
         VALUE dumped2;
-        int idx;
         if (ec->last_error.result == econv_incomplete_input) {
             mesg = rb_sprintf("incomplete %s on %s",
                     StringValueCStr(dumped),
@@ -2071,17 +2070,7 @@ make_econv_exception(rb_econv_t *ec) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2070
         rb_ivar_set(exc, rb_intern("error_bytes"), bytes);
         rb_ivar_set(exc, rb_intern("readagain_bytes"), bytes2);
         rb_ivar_set(exc, rb_intern("incomplete_input"), ec->last_error.result == econv_incomplete_input ? Qtrue : Qfalse);
-
-      set_encs:
-        rb_ivar_set(exc, rb_intern("source_encoding_name"), rb_str_new2(ec->last_error.source_encoding));
-        rb_ivar_set(exc, rb_intern("destination_encoding_name"), rb_str_new2(ec->last_error.destination_encoding));
-        idx = rb_enc_find_index(ec->last_error.source_encoding);
-        if (0 <= idx)
-            rb_ivar_set(exc, rb_intern("source_encoding"), rb_enc_from_encoding(rb_enc_from_index(idx)));
-        idx = rb_enc_find_index(ec->last_error.destination_encoding);
-        if (0 <= idx)
-            rb_ivar_set(exc, rb_intern("destination_encoding"), rb_enc_from_encoding(rb_enc_from_index(idx)));
-        return exc;
+        goto set_encs;
     }
     if (ec->last_error.result == econv_undefined_conversion) {
         VALUE bytes = rb_str_new((const char *)ec->last_error.error_bytes_start,
@@ -2133,6 +2122,17 @@ make_econv_exception(rb_econv_t *ec) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2122
         goto set_encs;
     }
     return Qnil;
+
+  set_encs:
+    rb_ivar_set(exc, rb_intern("source_encoding_name"), rb_str_new2(ec->last_error.source_encoding));
+    rb_ivar_set(exc, rb_intern("destination_encoding_name"), rb_str_new2(ec->last_error.destination_encoding));
+    int idx = rb_enc_find_index(ec->last_error.source_encoding);
+    if (0 <= idx)
+        rb_ivar_set(exc, rb_intern("source_encoding"), rb_enc_from_encoding(rb_enc_from_index(idx)));
+    idx = rb_enc_find_index(ec->last_error.destination_encoding);
+    if (0 <= idx)
+        rb_ivar_set(exc, rb_intern("destination_encoding"), rb_enc_from_encoding(rb_enc_from_index(idx)));
+    return exc;
 }
 
 static void
-- 
cgit v0.10.2


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

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