mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
92b8f4e293
commit
2ee075dc47
5 changed files with 7 additions and 12 deletions
|
|
@ -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()).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue