ddcb975ffc
Use closure parameter instead of external variable to remove 1 allocation. I tried to add test, but it is difficult to add something simple and not flake here. I did test this with: diff --git a/src/net/writev_test.go b/src/net/writev_test.go index 4c05be4..e417d68 100644 --- a/src/net/writev_test.go +++ b/src/net/writev_test.go @@ -99,6 +99,15 @@ func TestBuffers_WriteTo(t *testing.T) { } } +func TestBuffers_WriteToAllocs(t *testing.T) { + allocs := testing.AllocsPerRun(10, func() { + testBuffer_writeTo(t, 10, false) + }) + if allocs > 0 { + t.Fatalf("got %v; want 0", allocs) + } +} + func testBuffer_writeTo(t *testing.T, chunks int, useCopy bool) { oldHook := poll.TestHookDidWritev defer func() { poll.TestHookDidWritev = oldHook }() It makes allocation count go down by 1 after the fix. Before: C:\>u:\test -test.v -test.run=WriteToAllocs === RUN TestBuffers_WriteToAllocs --- FAIL: TestBuffers_WriteToAllocs (0.05s) writev_test.go:107: got 66; want 0 FAIL and after: C:\>u:\test -test.v -test.run=WriteToAllocs === RUN TestBuffers_WriteToAllocs --- FAIL: TestBuffers_WriteToAllocs (0.04s) writev_test.go:107: got 65; want 0 FAIL Thanks to @MichaelMonashev for report and the fix. Fixes #19222 Change-Id: I0f73cd9e2c8bbaa0653083f81f3ccb83b5ea84e1 Reviewed-on: https://go-review.googlesource.com/42893 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
favicon.ico | ||
LICENSE | ||
PATENTS | ||
README.md | ||
robots.txt |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.
Contributing
Go is the work of hundreds of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that the Go project does not use GitHub pull requests, and that we use the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.