From 6c3567873c4c58fe5b9e9abe77fed826a8e2ac97 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Tue, 27 Sep 2022 23:06:11 +0800 Subject: [PATCH] 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 --- src/runtime/testdata/testprog/traceback_ancestors.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) } -- 2.50.0