diff options
author | hopehook <hopehook.com@gmail.com> | 2022-09-07 22:34:48 +0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-09-08 21:16:39 +0000 |
commit | a9a398220ff387fe4924aee08365ffc374767a3a (patch) | |
tree | 7e87c5d5eb49cbcd2d3943a37a656a09893cc414 /src/hash | |
parent | 2c3187cd4295605033740ff0522b1457a702d84d (diff) | |
download | go-a9a398220ff387fe4924aee08365ffc374767a3a.tar.gz go-a9a398220ff387fe4924aee08365ffc374767a3a.zip |
all: use unsafe.{Slice, SliceData, String, StringData} to simplify code
Because most of these APIs are recently supported, we can only do some
advancement work as much as possible under the premise of compatibility.
For #54854.
Change-Id: Id15d11288bf23902570d54eaf2704a5264210b2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/429115
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: hopehook <hopehook@golangcn.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>
Diffstat (limited to 'src/hash')
-rw-r--r-- | src/hash/maphash/maphash.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/hash/maphash/maphash.go b/src/hash/maphash/maphash.go index dfacd021db..690068a70a 100644 --- a/src/hash/maphash/maphash.go +++ b/src/hash/maphash/maphash.go @@ -13,7 +13,6 @@ package maphash import ( - "internal/unsafeheader" "unsafe" ) @@ -72,11 +71,11 @@ func String(seed Seed, s string) uint64 { panic("maphash: use of uninitialized Seed") } for len(s) > bufSize { - p := (*byte)((*unsafeheader.String)(unsafe.Pointer(&s)).Data) + p := (*byte)(unsafe.StringData(s)) state = rthash(p, bufSize, state) s = s[bufSize:] } - p := (*byte)((*unsafeheader.String)(unsafe.Pointer(&s)).Data) + p := (*byte)(unsafe.StringData(s)) return rthash(p, len(s), state) } @@ -190,7 +189,7 @@ func (h *Hash) WriteString(s string) (int, error) { if len(s) > bufSize { h.initSeed() for len(s) > bufSize { - ptr := (*byte)((*unsafeheader.String)(unsafe.Pointer(&s)).Data) + ptr := (*byte)(unsafe.StringData(s)) h.state.s = rthash(ptr, bufSize, h.state.s) s = s[bufSize:] } |