]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: simplify code using unsafe.SliceData
authorcuiweixie <cuiweixie@gmail.com>
Sat, 3 Sep 2022 06:20:20 +0000 (14:20 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 7 Sep 2022 01:33:52 +0000 (01:33 +0000)
Updates #54854

Change-Id: I9c14f9fa595f73eae44eb714abc5d486915893c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/428155
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/bytes/bytes_test.go

index 05c7ccc50a5e82805f10cfbd3041c7c9f7d5bb5d..7263af3ed0160596627e4f2688698fed9971b036 100644 (file)
@@ -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)
                }
        }