diff options
| author | cuiweixie <cuiweixie@gmail.com> | 2022-09-03 14:35:41 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-09-07 01:33:55 +0000 |
| commit | 2ee075dc47ec686b48746fd261212b044705fcdc (patch) | |
| tree | dafd7bee1731faec7444a22b5fabfedefdd4cc53 /src/strings/clone_test.go | |
| parent | 92b8f4e293421b3b61e868d593a89315c788c327 (diff) | |
| download | go-2ee075dc47ec686b48746fd261212b044705fcdc.tar.xz | |
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>
Diffstat (limited to 'src/strings/clone_test.go')
| -rw-r--r-- | src/strings/clone_test.go | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/strings/clone_test.go b/src/strings/clone_test.go index a9ba8add23..77479cfacf 100644 --- a/src/strings/clone_test.go +++ b/src/strings/clone_test.go @@ -5,7 +5,6 @@ package strings_test import ( - "reflect" "strings" "testing" "unsafe" @@ -27,15 +26,12 @@ func TestClone(t *testing.T) { t.Errorf("Clone(%q) = %q; want %q", input, clone, input) } - inputHeader := (*reflect.StringHeader)(unsafe.Pointer(&input)) - cloneHeader := (*reflect.StringHeader)(unsafe.Pointer(&clone)) - if len(input) != 0 && cloneHeader.Data == inputHeader.Data { + if len(input) != 0 && unsafe.StringData(clone) == unsafe.StringData(input) { t.Errorf("Clone(%q) return value should not reference inputs backing memory.", input) } - emptyHeader := (*reflect.StringHeader)(unsafe.Pointer(&emptyString)) - if len(input) == 0 && cloneHeader.Data != emptyHeader.Data { - t.Errorf("Clone(%#v) return value should be equal to empty string.", inputHeader) + if len(input) == 0 && unsafe.StringData(clone) != unsafe.StringData(emptyString) { + t.Errorf("Clone(%#v) return value should be equal to empty string.", unsafe.StringData(input)) } } } |
