aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/string.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-04-24 17:04:32 -0700
committerKeith Randall <khr@golang.org>2016-04-25 21:16:52 +0000
commit6f3f02f80d23d3bbc2857be147341517d1762fbd (patch)
tree1dd0d232571ed10060d8d2f8fc65fe506f6750da /src/runtime/string.go
parent8b92397bcdcd5d6de3f72951a5514933fee32eb2 (diff)
downloadgo-6f3f02f80d23d3bbc2857be147341517d1762fbd.tar.gz
go-6f3f02f80d23d3bbc2857be147341517d1762fbd.zip
runtime: zero tmpbuf between len and cap
Zero the entire buffer so we don't need to lower its capacity upon return. This lets callers do some appending without allocation. Zeroing is cheap, the byte buffer requires only 4 extra instructions. Fixes #14235 Change-Id: I970d7badcef047dafac75ac17130030181f18fe2 Reviewed-on: https://go-review.googlesource.com/22424 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/string.go')
-rw-r--r--src/runtime/string.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/runtime/string.go b/src/runtime/string.go
index 112ce5d588..ef28ba9828 100644
--- a/src/runtime/string.go
+++ b/src/runtime/string.go
@@ -139,7 +139,8 @@ func slicebytetostringtmp(b []byte) string {
func stringtoslicebyte(buf *tmpBuf, s string) []byte {
var b []byte
if buf != nil && len(s) <= len(buf) {
- b = buf[:len(s):len(s)]
+ *buf = tmpBuf{}
+ b = buf[:len(s)]
} else {
b = rawbyteslice(len(s))
}
@@ -171,7 +172,8 @@ func stringtoslicerune(buf *[tmpStringBufSize]rune, s string) []rune {
}
var a []rune
if buf != nil && n <= len(buf) {
- a = buf[:n:n]
+ *buf = [tmpStringBufSize]rune{}
+ a = buf[:n]
} else {
a = rawruneslice(n)
}