Skip to content

Commit

Permalink
refactor: using unsafe.String and unsafe.SliceData (#21412)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie authored Sep 4, 2024
1 parent 292d7b4 commit d56bbb8
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### Improvements

* (client) [#21436](https://github.com/cosmos/cosmos-sdk/pull/21436) Use `address.Codec` from client.Context in `tx.Sign`.
* (internal) [#21412](https://github.com/cosmos/cosmos-sdk/pull/21412) Using unsafe.String and unsafe.SliceData.

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion 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/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 d56bbb8

Please sign in to comment.