From 7d1df8a6f93d6f90f33bead7304d45c854bb21fe Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Tue, 27 Aug 2024 21:24:11 +0800 Subject: [PATCH] refactor: using unsafe.String and unsafe.SliceData --- store/internal/conv/string.go | 2 +- store/v2/internal/conv/string.go | 2 +- x/authz/internal/conv/string.go | 2 +- x/nft/internal/conv/string.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/store/internal/conv/string.go b/store/internal/conv/string.go index 96d89c3a5ff..fa9e507be06 100644 --- a/store/internal/conv/string.go +++ b/store/internal/conv/string.go @@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte { // to be used generally, but for a specific pattern to delete keys // from a map. func UnsafeBytesToStr(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) } diff --git a/store/v2/internal/conv/string.go b/store/v2/internal/conv/string.go index 96d89c3a5ff..fa9e507be06 100644 --- a/store/v2/internal/conv/string.go +++ b/store/v2/internal/conv/string.go @@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte { // to be used generally, but for a specific pattern to delete keys // from a map. func UnsafeBytesToStr(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) } diff --git a/x/authz/internal/conv/string.go b/x/authz/internal/conv/string.go index 39078bd045b..5b76131c888 100644 --- a/x/authz/internal/conv/string.go +++ b/x/authz/internal/conv/string.go @@ -13,5 +13,5 @@ func UnsafeStrToBytes(s string) []byte { // to be used generally, but for a specific pattern to delete keys // from a map. func UnsafeBytesToStr(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) } diff --git a/x/nft/internal/conv/string.go b/x/nft/internal/conv/string.go index 96d89c3a5ff..fa9e507be06 100644 --- a/x/nft/internal/conv/string.go +++ b/x/nft/internal/conv/string.go @@ -15,5 +15,5 @@ func UnsafeStrToBytes(s string) []byte { // to be used generally, but for a specific pattern to delete keys // from a map. func UnsafeBytesToStr(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) }