From: cuiweixie Date: Tue, 27 Sep 2022 15:06:11 +0000 (+0800) Subject: runtime: using bytes.CutPrefix X-Git-Tag: go1.20rc1~904 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6c3567873c4c58fe5b9e9abe77fed826a8e2ac97;p=gostls13.git runtime: using bytes.CutPrefix Change-Id: I3f2dae17496b5b4efbdc022802f941a616abd87a Reviewed-on: https://go-review.googlesource.com/c/go/+/435276 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- diff --git a/src/runtime/testdata/testprog/traceback_ancestors.go b/src/runtime/testdata/testprog/traceback_ancestors.go index 1d0d00bab7..8fc1aa7dbb 100644 --- a/src/runtime/testdata/testprog/traceback_ancestors.go +++ b/src/runtime/testdata/testprog/traceback_ancestors.go @@ -87,9 +87,10 @@ func goroutineID() string { buf := make([]byte, 128) runtime.Stack(buf, false) prefix := []byte("goroutine ") - if !bytes.HasPrefix(buf, prefix) { + var found bool + if buf, found = bytes.CutPrefix(buf, prefix); !found { panic(fmt.Sprintf("expected %q at beginning of traceback:\n%s", prefix, buf)) } - id, _, _ := bytes.Cut(bytes.TrimPrefix(buf, prefix), []byte(" ")) + id, _, _ := bytes.Cut(buf, []byte(" ")) return string(id) }