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

ruby-changes:62053

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

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

From f12efec2c2698fb1ea775ce3d260a35628303833 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: Mon, 22 Jun 2020 10:57:01 +0900
Subject: vm_exec_handle_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/vm.c b/vm.c
index a6f8d92..6b78f54 100644
--- a/vm.c
+++ b/vm.c
@@ -2083,10 +2083,16 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L2083
 		}
 	    }
 	}
-	else if (state == TAG_BREAK && !escape_cfp) {
-	    type = CATCH_TYPE_BREAK;
+        else if ((state == TAG_BREAK && !escape_cfp) ||
+                 (state == TAG_REDO) ||
+                 (state == TAG_NEXT)) {
+            type = (const enum catch_type[TAG_MASK]) {
+                [TAG_BREAK]  = CATCH_TYPE_BREAK,
+                [TAG_NEXT]   = CATCH_TYPE_NEXT,
+                [TAG_REDO]   = CATCH_TYPE_REDO,
+                /* otherwise = dontcare */
+            }[state];
 
-	  search_restart_point:
 	    ct = cfp->iseq->body->catch_table;
 	    if (ct) for (i = 0; i < ct->size; i++) {
 		entry = UNALIGNED_MEMBER_PTR(ct, entries[i]);
@@ -2116,14 +2122,6 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L2122
 		}
 	    }
 	}
-	else if (state == TAG_REDO) {
-	    type = CATCH_TYPE_REDO;
-	    goto search_restart_point;
-	}
-	else if (state == TAG_NEXT) {
-	    type = CATCH_TYPE_NEXT;
-	    goto search_restart_point;
-	}
 	else {
 	    ct = cfp->iseq->body->catch_table;
 	    if (ct) for (i = 0; i < ct->size; i++) {
-- 
cgit v0.10.2


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

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