1
0
mirror of https://github.com/golang/go synced 2024-11-12 07:40:23 -07:00

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
This commit is contained in:
Richard Musiol 2014-02-06 14:44:30 -08:00 committed by Brad Fitzpatrick
parent 2b6eb111e2
commit 547a82c36c

View File

@ -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
}
}