diff options
author | Keith Randall <khr@google.com> | 2018-10-30 10:56:02 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2018-10-30 20:03:54 +0000 |
commit | 56b7c61c5e88e684c1bdb3b9ae61dadbeda96fd0 (patch) | |
tree | 9651f046cea2082ca590f82dac768170194039e2 /src/strings | |
parent | f14067f3c10e15343f29aed439ff60af856eb323 (diff) | |
download | go-56b7c61c5e88e684c1bdb3b9ae61dadbeda96fd0.tar.gz go-56b7c61c5e88e684c1bdb3b9ae61dadbeda96fd0.zip |
strings: declare IndexByte as noescape
This lets []byte->string conversions which are used as arguments to
strings.IndexByte and friends have their backing store allocated on
the stack.
It only prevents allocation when the string is small enough (32
bytes), so it isn't perfect. But reusing the []byte backing store
directly requires a bunch more compiler analysis (see #2205 and
related issues).
Fixes #25864.
Change-Id: Ie52430422196e3c91e5529d6e56a8435ced1fc4c
Reviewed-on: https://go-review.googlesource.com/c/146018
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/strings')
-rw-r--r-- | src/strings/strings_decl.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/strings/strings_decl.go b/src/strings/strings_decl.go index 98194445e1..6718c3ace4 100644 --- a/src/strings/strings_decl.go +++ b/src/strings/strings_decl.go @@ -4,5 +4,7 @@ package strings +//go:noescape + // IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s. func IndexByte(s string, c byte) int // in internal/bytealg |