aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/error.go1
-rw-r--r--src/runtime/string.go9
2 files changed, 4 insertions, 6 deletions
diff --git a/src/runtime/error.go b/src/runtime/error.go
index e1291e1543..2435f98b7a 100644
--- a/src/runtime/error.go
+++ b/src/runtime/error.go
@@ -121,6 +121,7 @@ func printany(i interface{}) {
// strings.IndexByte is implemented in runtime/asm_$goarch.s
// but amusingly we need go:linkname to get access to it here in the runtime.
//go:linkname stringsIndexByte strings.IndexByte
+//go:noescape
func stringsIndexByte(s string, c byte) int
// panicwrap generates a panic for a call to a wrapped value method
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 {