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

@ -660,8 +660,7 @@ func TestMap(t *testing.T) {
}
orig := "Input string that we expect not to be copied."
m = Map(identity, orig)
if (*reflect.StringHeader)(unsafe.Pointer(&orig)).Data !=
(*reflect.StringHeader)(unsafe.Pointer(&m)).Data {
if unsafe.StringData(orig) != unsafe.StringData(m) {
t.Error("unexpected copy during identity map")
}