22cfe24aca
The destination slice does not need to be created at all. The source slice itself can be used as the destination because the decode loop increments by one and then the 'seen' byte is not used anymore. Therefore the decoded byte can be stored in that index of the source slice itself. This trick cannot be applied to EncodeString() because in that case, the destination slice is large than the source. And for a single byte in the source slice, two bytes in the destination slice is written. func BenchmarkDecodeString(b *testing.B) { for i := 0; i < b.N; i++ { DecodeString("0123456789abcdef") } } name old time/op new time/op delta DecodeString 71.0ns ± 6% 58.0ns ± 0% -18.28% (p=0.008 n=5+5) name old alloc/op new alloc/op delta DecodeString 16.0B ± 0% 8.0B ± 0% -50.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta DecodeString 1.00 ± 0% 1.00 ± 0% ~ (all equal) Change-Id: Id98db4e712444557a804155457a4dd8d1b8b416d Reviewed-on: https://go-review.googlesource.com/55611 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@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.