Commit b0dc5469 authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Brad Fitzpatrick

runtime: replace calls to hasprefix with hasPrefix

The hasprefix function is redundant and can be removed since it has
the same implementation as hasPrefix modulo variable names.

Fixes #25688

Change-Id: I499cc24a2b5c38d1301718a4e66f555fd138386f
Reviewed-on: https://go-review.googlesource.com/115835
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIlya Tocar <ilya.tocar@intel.com>
parent 2fad8b21
...@@ -115,7 +115,7 @@ func (h *debugCallHandler) handle(info *siginfo, ctxt *sigctxt, gp2 *g) bool { ...@@ -115,7 +115,7 @@ func (h *debugCallHandler) handle(info *siginfo, ctxt *sigctxt, gp2 *g) bool {
return false return false
} }
f := findfunc(uintptr(ctxt.rip())) f := findfunc(uintptr(ctxt.rip()))
if !(hasprefix(funcname(f), "runtime.debugCall") || hasprefix(funcname(f), "debugCall")) { if !(hasPrefix(funcname(f), "runtime.debugCall") || hasPrefix(funcname(f), "debugCall")) {
println("trap in unknown function", funcname(f)) println("trap in unknown function", funcname(f))
return false return false
} }
......
...@@ -44,7 +44,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int { ...@@ -44,7 +44,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
// level by the program but will otherwise be ignored. // level by the program but will otherwise be ignored.
flags = _SigNotify flags = _SigNotify
for sig, t = range sigtable { for sig, t = range sigtable {
if hasprefix(notestr, t.name) { if hasPrefix(notestr, t.name) {
flags = t.flags flags = t.flags
break break
} }
......
...@@ -112,20 +112,20 @@ func sigpanic() { ...@@ -112,20 +112,20 @@ func sigpanic() {
} }
func atolwhex(p string) int64 { func atolwhex(p string) int64 {
for hasprefix(p, " ") || hasprefix(p, "\t") { for hasPrefix(p, " ") || hasPrefix(p, "\t") {
p = p[1:] p = p[1:]
} }
neg := false neg := false
if hasprefix(p, "-") || hasprefix(p, "+") { if hasPrefix(p, "-") || hasPrefix(p, "+") {
neg = p[0] == '-' neg = p[0] == '-'
p = p[1:] p = p[1:]
for hasprefix(p, " ") || hasprefix(p, "\t") { for hasPrefix(p, " ") || hasPrefix(p, "\t") {
p = p[1:] p = p[1:]
} }
} }
var n int64 var n int64
switch { switch {
case hasprefix(p, "0x"), hasprefix(p, "0X"): case hasPrefix(p, "0x"), hasPrefix(p, "0X"):
p = p[2:] p = p[2:]
for ; len(p) > 0; p = p[1:] { for ; len(p) > 0; p = p[1:] {
if '0' <= p[0] && p[0] <= '9' { if '0' <= p[0] && p[0] <= '9' {
...@@ -138,7 +138,7 @@ func atolwhex(p string) int64 { ...@@ -138,7 +138,7 @@ func atolwhex(p string) int64 {
break break
} }
} }
case hasprefix(p, "0"): case hasPrefix(p, "0"):
for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] { for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] {
n = n*8 + int64(p[0]-'0') n = n*8 + int64(p[0]-'0')
} }
......
...@@ -498,7 +498,7 @@ func cpuinit() { ...@@ -498,7 +498,7 @@ func cpuinit() {
p := argv_index(argv, argc+1+i) p := argv_index(argv, argc+1+i)
s := *(*string)(unsafe.Pointer(&stringStruct{unsafe.Pointer(p), findnull(p)})) s := *(*string)(unsafe.Pointer(&stringStruct{unsafe.Pointer(p), findnull(p)}))
if hasprefix(s, prefix) { if hasPrefix(s, prefix) {
env = gostring(p)[len(prefix):] env = gostring(p)[len(prefix):]
break break
} }
...@@ -3702,7 +3702,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { ...@@ -3702,7 +3702,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
// received from somewhere else (with _LostSIGPROFDuringAtomic64 as pc). // received from somewhere else (with _LostSIGPROFDuringAtomic64 as pc).
if GOARCH == "mips" || GOARCH == "mipsle" || GOARCH == "arm" { if GOARCH == "mips" || GOARCH == "mipsle" || GOARCH == "arm" {
if f := findfunc(pc); f.valid() { if f := findfunc(pc); f.valid() {
if hasprefix(funcname(f), "runtime/internal/atomic") { if hasPrefix(funcname(f), "runtime/internal/atomic") {
lostAtomic64Count++ lostAtomic64Count++
return return
} }
......
...@@ -333,7 +333,7 @@ func index(s, t string) int { ...@@ -333,7 +333,7 @@ func index(s, t string) int {
return 0 return 0
} }
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
if s[i] == t[0] && hasprefix(s[i:], t) { if s[i] == t[0] && hasPrefix(s[i:], t) {
return i return i
} }
} }
...@@ -344,8 +344,8 @@ func contains(s, t string) bool { ...@@ -344,8 +344,8 @@ func contains(s, t string) bool {
return index(s, t) >= 0 return index(s, t) >= 0
} }
func hasprefix(s, t string) bool { func hasPrefix(s, prefix string) bool {
return len(s) >= len(t) && s[:len(t)] == t return len(s) >= len(prefix) && s[:len(prefix)] == prefix
} }
const ( const (
......
...@@ -843,7 +843,7 @@ func showfuncinfo(f funcInfo, firstFrame, elideWrapper bool) bool { ...@@ -843,7 +843,7 @@ func showfuncinfo(f funcInfo, firstFrame, elideWrapper bool) bool {
return true return true
} }
return contains(name, ".") && (!hasprefix(name, "runtime.") || isExportedRuntime(name)) return contains(name, ".") && (!hasPrefix(name, "runtime.") || isExportedRuntime(name))
} }
// isExportedRuntime reports whether name is an exported runtime function. // isExportedRuntime reports whether name is an exported runtime function.
...@@ -1022,7 +1022,7 @@ func isSystemGoroutine(gp *g) bool { ...@@ -1022,7 +1022,7 @@ func isSystemGoroutine(gp *g) bool {
// back into user code. // back into user code.
return !fingRunning return !fingRunning
} }
return hasprefix(funcname(f), "runtime.") return hasPrefix(funcname(f), "runtime.")
} }
// SetCgoTraceback records three C functions to use to gather // SetCgoTraceback records three C functions to use to gather
......
...@@ -112,10 +112,6 @@ func (t *_type) uncommon() *uncommontype { ...@@ -112,10 +112,6 @@ func (t *_type) uncommon() *uncommontype {
} }
} }
func hasPrefix(s, prefix string) bool {
return len(s) >= len(prefix) && s[:len(prefix)] == prefix
}
func (t *_type) name() string { func (t *_type) name() string {
if t.tflag&tflagNamed == 0 { if t.tflag&tflagNamed == 0 {
return "" return ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment