]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use unsafe.{String,StringData} in arena test
authorIan Lance Taylor <iant@golang.org>
Thu, 8 Jun 2023 20:11:31 +0000 (13:11 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 20 Jul 2023 18:02:29 +0000 (18:02 +0000)
Change-Id: Ia567b163efe7b323694c15abcf0cef0effc6ff6a
Reviewed-on: https://go-review.googlesource.com/c/go/+/501995
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/runtime/arena_test.go

index 7e121ada714f6465fe6f1e870a7a02313ca05c9a..018c42371256325d50ce86d86422ebf9986433a1 100644 (file)
@@ -390,21 +390,18 @@ func TestUserArenaCloneString(t *testing.T) {
        // Create a string as using the same memory as the byte slice, hence in
        // the arena. This could be an arena API, but hasn't really been needed
        // yet.
-       var as string
-       asHeader := (*reflect.StringHeader)(unsafe.Pointer(&as))
-       asHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(&b)).Data
-       asHeader.Len = len(b)
+       as := unsafe.String(&b[0], len(b))
 
        // Clone should make a copy of as, since it is in the arena.
        asCopy := UserArenaClone(as)
-       if (*reflect.StringHeader)(unsafe.Pointer(&as)).Data == (*reflect.StringHeader)(unsafe.Pointer(&asCopy)).Data {
+       if unsafe.StringData(as) == unsafe.StringData(asCopy) {
                t.Error("Clone did not make a copy")
        }
 
        // Clone should make a copy of subAs, since subAs is just part of as and so is in the arena.
        subAs := as[1:3]
        subAsCopy := UserArenaClone(subAs)
-       if (*reflect.StringHeader)(unsafe.Pointer(&subAs)).Data == (*reflect.StringHeader)(unsafe.Pointer(&subAsCopy)).Data {
+       if unsafe.StringData(subAs) == unsafe.StringData(subAsCopy) {
                t.Error("Clone did not make a copy")
        }
        if len(subAs) != len(subAsCopy) {
@@ -420,13 +417,13 @@ func TestUserArenaCloneString(t *testing.T) {
        // Clone should not make a copy of doubleAs, since doubleAs will be on the heap.
        doubleAs := as + as
        doubleAsCopy := UserArenaClone(doubleAs)
-       if (*reflect.StringHeader)(unsafe.Pointer(&doubleAs)).Data != (*reflect.StringHeader)(unsafe.Pointer(&doubleAsCopy)).Data {
+       if unsafe.StringData(doubleAs) != unsafe.StringData(doubleAsCopy) {
                t.Error("Clone should not have made a copy")
        }
 
        // Clone should not make a copy of s, since s is a static string.
        sCopy := UserArenaClone(s)
-       if (*reflect.StringHeader)(unsafe.Pointer(&s)).Data != (*reflect.StringHeader)(unsafe.Pointer(&sCopy)).Data {
+       if unsafe.StringData(s) != unsafe.StringData(sCopy) {
                t.Error("Clone should not have made a copy")
        }