Skip to content

Commit

Permalink
refactor: using unsafe.String and unsafe.SliceData
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie committed Aug 28, 2024
1 parent f02a173 commit 7d1df8a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion store/internal/conv/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion store/v2/internal/conv/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion x/authz/internal/conv/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion x/nft/internal/conv/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 7d1df8a

Please sign in to comment.