]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make use of stringslite.{HasPrefix, HasSuffix}
authorJes Cok <xigua67damn@gmail.com>
Tue, 14 May 2024 18:37:41 +0000 (02:37 +0800)
committerMichael Knyszek <mknyszek@google.com>
Fri, 17 May 2024 15:41:45 +0000 (15:41 +0000)
Change-Id: I7461a892e1591e3bad876f0a718a99e6de2c4659
Reviewed-on: https://go-review.googlesource.com/c/go/+/585435
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/internal/objabi/pkgspecial.go
src/runtime/export_debug_test.go
src/runtime/os3_plan9.go
src/runtime/os_plan9.go
src/runtime/panic.go
src/runtime/preempt.go
src/runtime/proc.go
src/runtime/security_unix.go
src/runtime/string.go
src/runtime/symtabinl_test.go
src/runtime/traceback.go

index 867d92d357c25d61d9c6d41890c83897a150f0eb..6c2425d3ffa380e2f19281c11c5767e740ed1397 100644 (file)
@@ -58,6 +58,7 @@ var runtimePkgs = []string{
        "internal/godebugs",
        "internal/goexperiment",
        "internal/goos",
+       "internal/stringslite",
 }
 
 // extraNoInstrumentPkgs is the set of packages in addition to runtimePkgs that
index 810a5a64351501874a72692b0c3fa3ff4ae9e377..4e0a4ef97e9d076cb2346ba219f0b636c4ed8e33 100644 (file)
@@ -8,6 +8,7 @@ package runtime
 
 import (
        "internal/abi"
+       "internal/stringslite"
        "unsafe"
 )
 
@@ -145,7 +146,7 @@ func (h *debugCallHandler) handle(info *siginfo, ctxt *sigctxt, gp2 *g) bool {
                return false
        }
        f := findfunc(ctxt.sigpc())
-       if !(hasPrefix(funcname(f), "runtime.debugCall") || hasPrefix(funcname(f), "debugCall")) {
+       if !(stringslite.HasPrefix(funcname(f), "runtime.debugCall") || stringslite.HasPrefix(funcname(f), "debugCall")) {
                println("trap in unknown function", funcname(f))
                return false
        }
index 8c9cbe28ec2fb75196471bc6eb842768f2b836ed..dd1570561803f8947ec051b8180a06c19634969a 100644 (file)
@@ -7,6 +7,7 @@ package runtime
 import (
        "internal/abi"
        "internal/goarch"
+       "internal/stringslite"
        "unsafe"
 )
 
@@ -47,7 +48,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
        // level by the program but will otherwise be ignored.
        flags = _SigNotify
        for sig, t = range sigtable {
-               if hasPrefix(notestr, t.name) {
+               if stringslite.HasPrefix(notestr, t.name) {
                        flags = t.flags
                        break
                }
index 5e355f1664503718b2e9cef684208880cc659b33..2dbb42ad037d1f1ca63a4d930004fa8868dff2de 100644 (file)
@@ -7,6 +7,7 @@ package runtime
 import (
        "internal/abi"
        "internal/runtime/atomic"
+       "internal/stringslite"
        "unsafe"
 )
 
@@ -124,7 +125,7 @@ func indexNoFloat(s, t string) int {
                return 0
        }
        for i := 0; i < len(s); i++ {
-               if s[i] == t[0] && hasPrefix(s[i:], t) {
+               if s[i] == t[0] && stringslite.HasPrefix(s[i:], t) {
                        return i
                }
        }
@@ -132,20 +133,20 @@ func indexNoFloat(s, t string) int {
 }
 
 func atolwhex(p string) int64 {
-       for hasPrefix(p, " ") || hasPrefix(p, "\t") {
+       for stringslite.HasPrefix(p, " ") || stringslite.HasPrefix(p, "\t") {
                p = p[1:]
        }
        neg := false
-       if hasPrefix(p, "-") || hasPrefix(p, "+") {
+       if stringslite.HasPrefix(p, "-") || stringslite.HasPrefix(p, "+") {
                neg = p[0] == '-'
                p = p[1:]
-               for hasPrefix(p, " ") || hasPrefix(p, "\t") {
+               for stringslite.HasPrefix(p, " ") || stringslite.HasPrefix(p, "\t") {
                        p = p[1:]
                }
        }
        var n int64
        switch {
-       case hasPrefix(p, "0x"), hasPrefix(p, "0X"):
+       case stringslite.HasPrefix(p, "0x"), stringslite.HasPrefix(p, "0X"):
                p = p[2:]
                for ; len(p) > 0; p = p[1:] {
                        if '0' <= p[0] && p[0] <= '9' {
@@ -158,7 +159,7 @@ func atolwhex(p string) int64 {
                                break
                        }
                }
-       case hasPrefix(p, "0"):
+       case stringslite.HasPrefix(p, "0"):
                for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] {
                        n = n*8 + int64(p[0]-'0')
                }
index ff9c64113fafeac5fac772f8a631359b97b19def..58d13b6adb9e4b36a48182d68a30158f47e6e50b 100644 (file)
@@ -8,6 +8,7 @@ import (
        "internal/abi"
        "internal/goarch"
        "internal/runtime/atomic"
+       "internal/stringslite"
        "runtime/internal/sys"
        "unsafe"
 )
@@ -53,7 +54,7 @@ const (
 // pc should be the program counter of the compiler-generated code that
 // triggered this panic.
 func panicCheck1(pc uintptr, msg string) {
-       if goarch.IsWasm == 0 && hasPrefix(funcname(findfunc(pc)), "runtime.") {
+       if goarch.IsWasm == 0 && stringslite.HasPrefix(funcname(findfunc(pc)), "runtime.") {
                // Note: wasm can't tail call, so we can't get the original caller's pc.
                throw(msg)
        }
index 82d85cd707619a5e140c018ad005f7e9e2c5779f..45b1b5e9c7d42c0eeaae5ccc0e9010b096f0b770 100644 (file)
@@ -55,6 +55,7 @@ package runtime
 import (
        "internal/abi"
        "internal/goarch"
+       "internal/stringslite"
 )
 
 type suspendGState struct {
@@ -416,9 +417,9 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) (bool, uintptr) {
        // Check the inner-most name
        u, uf := newInlineUnwinder(f, pc)
        name := u.srcFunc(uf).name()
-       if hasPrefix(name, "runtime.") ||
-               hasPrefix(name, "runtime/internal/") ||
-               hasPrefix(name, "reflect.") {
+       if stringslite.HasPrefix(name, "runtime.") ||
+               stringslite.HasPrefix(name, "runtime/internal/") ||
+               stringslite.HasPrefix(name, "reflect.") {
                // For now we never async preempt the runtime or
                // anything closely tied to the runtime. Known issues
                // include: various points in the scheduler ("don't
index 140f06d03d76aec03f4d640fd01b7d4c63ff3983..67cd6aea783681efa2f8056142064a121db58c27 100644 (file)
@@ -10,6 +10,7 @@ import (
        "internal/goarch"
        "internal/goos"
        "internal/runtime/atomic"
+       "internal/stringslite"
        "runtime/internal/sys"
        "unsafe"
 )
@@ -729,7 +730,7 @@ func getGodebugEarly() string {
                        p := argv_index(argv, argc+1+i)
                        s := unsafe.String(p, findnull(p))
 
-                       if hasPrefix(s, prefix) {
+                       if stringslite.HasPrefix(s, prefix) {
                                env = gostring(p)[len(prefix):]
                                break
                        }
@@ -5268,7 +5269,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
        // received from somewhere else (with _LostSIGPROFDuringAtomic64 as pc).
        if GOARCH == "mips" || GOARCH == "mipsle" || GOARCH == "arm" {
                if f := findfunc(pc); f.valid() {
-                       if hasPrefix(funcname(f), "internal/runtime/atomic") {
+                       if stringslite.HasPrefix(funcname(f), "internal/runtime/atomic") {
                                cpuprof.lostAtomic++
                                return
                        }
index fa54090df248579d8509e69208f196a376eb7326..6ef3b5b328c64507d4ed79a64de6b3bb835000a9 100644 (file)
@@ -6,6 +6,10 @@
 
 package runtime
 
+import (
+       "internal/stringslite"
+)
+
 func secure() {
        initSecureMode()
 
@@ -25,7 +29,7 @@ func secure() {
 func secureEnv() {
        var hasTraceback bool
        for i := 0; i < len(envs); i++ {
-               if hasPrefix(envs[i], "GOTRACEBACK=") {
+               if stringslite.HasPrefix(envs[i], "GOTRACEBACK=") {
                        hasTraceback = true
                        envs[i] = "GOTRACEBACK=none"
                }
index 81d1b80e56030bdb101cafbac847238a776f7dc1..d45888b7a8efa27a83874c49d299b7b2a499aa66 100644 (file)
@@ -341,14 +341,6 @@ func gostringn(p *byte, l int) string {
        return s
 }
 
-func hasPrefix(s, prefix string) bool {
-       return len(s) >= len(prefix) && s[:len(prefix)] == prefix
-}
-
-func hasSuffix(s, suffix string) bool {
-       return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
-}
-
 const (
        maxUint64 = ^uint64(0)
        maxInt64  = int64(maxUint64 >> 1)
index df524aec4a039b5378679001caf2844bf23c3947..3c7cb2e595b99ed782abfc483a9a64bce0b9f246 100644 (file)
@@ -6,6 +6,7 @@ package runtime
 
 import (
        "internal/abi"
+       "internal/stringslite"
        "runtime/internal/sys"
 )
 
@@ -50,7 +51,7 @@ func XTestInlineUnwinder(t TestingT) {
                for ; uf.valid(); uf = u.next(uf) {
                        file, line := u.fileLine(uf)
                        const wantFile = "symtabinl_test.go"
-                       if !hasSuffix(file, wantFile) {
+                       if !stringslite.HasSuffix(file, wantFile) {
                                t.Errorf("tiuTest+%#x: want file ...%s, got %s", pc-pc1, wantFile, file)
                        }
 
@@ -58,10 +59,10 @@ func XTestInlineUnwinder(t TestingT) {
 
                        name := sf.name()
                        const namePrefix = "runtime."
-                       if hasPrefix(name, namePrefix) {
+                       if stringslite.HasPrefix(name, namePrefix) {
                                name = name[len(namePrefix):]
                        }
-                       if !hasPrefix(name, "tiu") {
+                       if !stringslite.HasPrefix(name, "tiu") {
                                t.Errorf("tiuTest+%#x: unexpected function %s", pc-pc1, name)
                        }
 
index 100662f2748707ae5869a8c1b6c64787e073f31b..ebee16c6a738ab49ee6eebd2636fbafa05f68052 100644 (file)
@@ -8,6 +8,7 @@ import (
        "internal/abi"
        "internal/bytealg"
        "internal/goarch"
+       "internal/stringslite"
        "runtime/internal/sys"
        "unsafe"
 )
@@ -1131,7 +1132,7 @@ func showfuncinfo(sf srcFunc, firstFrame bool, calleeID abi.FuncID) bool {
                return true
        }
 
-       return bytealg.IndexByteString(name, '.') >= 0 && (!hasPrefix(name, "runtime.") || isExportedRuntime(name))
+       return bytealg.IndexByteString(name, '.') >= 0 && (!stringslite.HasPrefix(name, "runtime.") || isExportedRuntime(name))
 }
 
 // isExportedRuntime reports whether name is an exported runtime function.
@@ -1342,7 +1343,7 @@ func isSystemGoroutine(gp *g, fixed bool) bool {
                }
                return fingStatus.Load()&fingRunningFinalizer == 0
        }
-       return hasPrefix(funcname(f), "runtime.")
+       return stringslite.HasPrefix(funcname(f), "runtime.")
 }
 
 // SetCgoTraceback records three C functions to use to gather