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

ruby-changes:62035

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

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

From cc27cd26d728d285aed728e730994d31f5ac1241 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: Tue, 16 Jun 2020 13:02:03 +0900
Subject: rand_range: 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/random.c b/random.c
index 708f5c4..8a59d1c 100644
--- a/random.c
+++ b/random.c
@@ -1169,8 +1169,8 @@ rand_range(VALUE obj, rb_random_t* rnd, VALUE range) https://github.com/ruby/ruby/blob/trunk/random.c#L1169
 	long max;
 	vmax = v;
 	v = Qnil;
+      fixnum:
 	if (FIXNUM_P(vmax)) {
-	  fixnum:
 	    if ((max = FIX2LONG(vmax) - excl) >= 0) {
 		unsigned long r = random_ulong_limited(obj, rnd, (unsigned long)max);
 		v = ULONG2NUM(r);
-- 
cgit v0.10.2


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

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