ruby-changes:61985
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:06:32 +0900 (JST)
Subject: [ruby-changes:61985] a93da4970b (master): cmp_clamp: do not goto into a branch
https://git.ruby-lang.org/ruby.git/commit/?id=a93da4970b From a93da4970be44a473b7b42e7516eb2663dece2c3 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, 11 Jun 2020 14:20:24 +0900 Subject: cmp_clamp: 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/compar.c b/compar.c index 15ebfcd..6e64e3d 100644 --- a/compar.c +++ b/compar.c @@ -233,11 +233,9 @@ cmp_clamp(int argc, VALUE *argv, VALUE x) https://github.com/ruby/ruby/blob/trunk/compar.c#L233 } if (!NIL_P(max)) { if (excl) rb_raise(rb_eArgError, "cannot clamp with an exclusive range"); - if (!NIL_P(min) && cmpint(min, max) > 0) goto arg_error; } } - else if (cmpint(min, max) > 0) { - arg_error: + if (!NIL_P(min) && !NIL_P(max) && cmpint(min, max) > 0) { rb_raise(rb_eArgError, "min argument must be smaller than max argument"); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/