]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: replace goto with for loop
authorRichard Musiol <mail@richard-musiol.de>
Thu, 6 Feb 2014 22:44:30 +0000 (14:44 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 6 Feb 2014 22:44:30 +0000 (14:44 -0800)
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

index f316806d7cae7d8fb52154efe50ba681cdc1e2f6..3d5a8682d94c53fa6c4c5f9d11ff80a4a80d0650 100644 (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
                }
        }