From 547a82c36cbeb59544943848ec6c5cadbe0b770a Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Thu, 6 Feb 2014 14:44:30 -0800 Subject: [PATCH] math/big: replace goto with for loop I just added support for goto statements to my GopherJS project and now I am trying to get rid of my patches. These occurrences of goto however are a bit problematic: GopherJS has to emulate gotos, so there is some performance drawback when doing so. In this case the drawback is major, since this is a core function of math/big which is called quite often. Additionally I can't see any reason here why the implementation with gotos should be preferred over my proposal. That's why I would kindly ask to include this patch, even though it is functional equivalent to the existing code. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/55470046 --- src/pkg/math/big/arith.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pkg/math/big/arith.go b/src/pkg/math/big/arith.go index f316806d7c..3d5a8682d9 100644 --- a/src/pkg/math/big/arith.go +++ b/src/pkg/math/big/arith.go @@ -131,12 +131,11 @@ func divWW_g(u1, u0, v Word) (q, r Word) { q1 := un32 / vn1 rhat := un32 - q1*vn1 -again1: - if q1 >= _B2 || q1*vn0 > _B2*rhat+un1 { + for q1 >= _B2 || q1*vn0 > _B2*rhat+un1 { q1-- rhat += vn1 - if rhat < _B2 { - goto again1 + if rhat >= _B2 { + break } } @@ -144,12 +143,11 @@ again1: q0 := un21 / vn1 rhat = un21 - q0*vn1 -again2: - if q0 >= _B2 || q0*vn0 > _B2*rhat+un0 { + for q0 >= _B2 || q0*vn0 > _B2*rhat+un0 { q0-- rhat += vn1 - if rhat < _B2 { - goto again2 + if rhat >= _B2 { + break } }