From: cuiweixie Date: Sat, 3 Sep 2022 06:20:20 +0000 (+0800) Subject: bytes: simplify code using unsafe.SliceData X-Git-Tag: go1.20rc1~1161 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2a627afe139b9e7b079da14b30beeb0bb8f5d09e;p=gostls13.git bytes: simplify code using unsafe.SliceData Updates #54854 Change-Id: I9c14f9fa595f73eae44eb714abc5d486915893c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/428155 Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor --- diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go index 05c7ccc50a..7263af3ed0 100644 --- a/src/bytes/bytes_test.go +++ b/src/bytes/bytes_test.go @@ -2186,9 +2186,7 @@ func TestClone(t *testing.T) { t.Errorf("Clone(%#v) return value should not be equal to nil slice.", input) } - inputHeader := (*reflect.SliceHeader)(unsafe.Pointer(&input)) - cloneHeader := (*reflect.SliceHeader)(unsafe.Pointer(&clone)) - if cap(input) != 0 && cloneHeader.Data == inputHeader.Data { + if cap(input) != 0 && unsafe.SliceData(input) == unsafe.SliceData(clone) { t.Errorf("Clone(%q) return value should not reference inputs backing memory.", input) } }