mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: replace index and contains with bytealg calls
The runtime has its own implementation of string indexing. To reduce code duplication and cognitive load, replace this with calls to the internal/bytealg package. We can't do this on Plan 9 because it needs string indexing in a note handler (which isn't allowed to use the optimized bytealg version because it uses SSE), so we can't just eliminate the index function, but this CL does down-scope it so make it clear it's only for note handlers on Plan 9. Change-Id: Ie1a142678262048515c481e8c26313b80c5875df Reviewed-on: https://go-review.googlesource.com/c/go/+/244537 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
dc12d5b0f5
commit
7bbd5ca5a6
5 changed files with 23 additions and 22 deletions
|
|
@ -82,10 +82,10 @@ func sigpanic() {
|
|||
note := gostringnocopy((*byte)(unsafe.Pointer(g.m.notesig)))
|
||||
switch g.sig {
|
||||
case _SIGRFAULT, _SIGWFAULT:
|
||||
i := index(note, "addr=")
|
||||
i := indexNoFloat(note, "addr=")
|
||||
if i >= 0 {
|
||||
i += 5
|
||||
} else if i = index(note, "va="); i >= 0 {
|
||||
} else if i = indexNoFloat(note, "va="); i >= 0 {
|
||||
i += 3
|
||||
} else {
|
||||
panicmem()
|
||||
|
|
@ -111,6 +111,20 @@ func sigpanic() {
|
|||
}
|
||||
}
|
||||
|
||||
// indexNoFloat is bytealg.IndexString but safe to use in a note
|
||||
// handler.
|
||||
func indexNoFloat(s, t string) int {
|
||||
if len(t) == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == t[0] && hasPrefix(s[i:], t) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func atolwhex(p string) int64 {
|
||||
for hasPrefix(p, " ") || hasPrefix(p, "\t") {
|
||||
p = p[1:]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue