diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2018-02-13 17:54:05 -0800 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2018-03-01 20:34:07 +0000 |
commit | 7365fac2dbd01960268ee051ed03d961258d4ef4 (patch) | |
tree | 26075f6023cdf143f3e60c7329f4843a88f0577e /src/runtime/string.go | |
parent | 39fefa0709474d291af65af13bd2ac408ef5e9eb (diff) | |
download | go-7365fac2dbd01960268ee051ed03d961258d4ef4.tar.gz go-7365fac2dbd01960268ee051ed03d961258d4ef4.zip |
runtime: use bytes.IndexByte in findnull
bytes.IndexByte is heavily optimized.
Use it in findnull.
name old time/op new time/op delta
GoString-8 65.5ns ± 1% 40.2ns ± 1% -38.62% (p=0.000 n=19+19)
findnull is also used in gostringnocopy,
which is used in many hot spots in the runtime.
Fixes #23830
Change-Id: I2e6cb279c7d8078f8844065de684cc3567fe89d7
Reviewed-on: https://go-review.googlesource.com/97523
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/string.go')
-rw-r--r-- | src/runtime/string.go | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/runtime/string.go b/src/runtime/string.go index 5c83895995..0ea162235c 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -407,12 +407,9 @@ func findnull(s *byte) int { if s == nil { return 0 } - p := (*[maxAlloc/2 - 1]byte)(unsafe.Pointer(s)) - l := 0 - for p[l] != 0 { - l++ - } - return l + ss := stringStruct{unsafe.Pointer(s), maxAlloc/2 - 1} + t := *(*string)(unsafe.Pointer(&ss)) + return stringsIndexByte(t, 0) } func findnullw(s *uint16) int { |