]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: revert a goto for-loop
authorDaniel Martí <mvdan@mvdan.cc>
Fri, 16 Oct 2020 14:05:04 +0000 (15:05 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 16 Oct 2020 14:23:21 +0000 (14:23 +0000)
In https://golang.org/cl/16528, a goto loop was chosen over a regular
for loop since that would make the function inlinable.

Thanks to the recent https://golang.org/cl/256459, for loops without a
label can now be inlined. So we can undo the workaround and simplify the
code.

Also add the function to TestIntendedInlining, which passes both before
and after the change, as expected.

For #14768.

Change-Id: Ie5df55a6bcb07c538ca331eef2f908807ff0b516
Reviewed-on: https://go-review.googlesource.com/c/go/+/263037
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/gc/inl_test.go
src/compress/flate/dict_decoder.go

index 547a602ee04102aebfd48b6eec2ccbbdfdf44997..afa6b983151f3233040c3d3b6fe667be7795edee 100644 (file)
@@ -115,6 +115,7 @@ func TestIntendedInlining(t *testing.T) {
                        "byLiteral.Len",
                        "byLiteral.Less",
                        "byLiteral.Swap",
+                       "(*dictDecoder).tryWriteCopy",
                },
                "encoding/base64": {
                        "assemble32",
index 71c75a065ea7f7620a36bc10bb16abeda9873577..3b59d48351123cc0e5a43f86dd5fad17bb650d79 100644 (file)
@@ -160,10 +160,8 @@ func (dd *dictDecoder) tryWriteCopy(dist, length int) int {
        srcPos := dstPos - dist
 
        // Copy possibly overlapping section before destination position.
-loop:
-       dstPos += copy(dd.hist[dstPos:endPos], dd.hist[srcPos:dstPos])
-       if dstPos < endPos {
-               goto loop // Avoid for-loop so that this function can be inlined
+       for dstPos < endPos {
+               dstPos += copy(dd.hist[dstPos:endPos], dd.hist[srcPos:dstPos])
        }
 
        dd.wrPos = dstPos