strings: simplify code using unsafe.StringData

Updates #54854

Change-Id: I93396dc92bd2decba895f2d059e1aeffcd22312c
Reviewed-on: https://go-review.googlesource.com/c/go/+/428158
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
cuiweixie 2022-09-03 14:35:41 +08:00 committed by Gopher Robot
parent 92b8f4e293
commit 2ee075dc47
5 changed files with 7 additions and 12 deletions

View file

@ -45,7 +45,7 @@ func (b *Builder) copyCheck() {
// String returns the accumulated string.
func (b *Builder) String() string {
return *(*string)(unsafe.Pointer(&b.buf))
return unsafe.String(unsafe.SliceData(b.buf), len(b.buf))
}
// Len returns the number of accumulated bytes; b.Len() == len(b.String()).