diff --git a/util/gconv/gconv_unsafe.go b/util/gconv/gconv_unsafe.go index e4b24fdfc..4381ddffc 100644 --- a/util/gconv/gconv_unsafe.go +++ b/util/gconv/gconv_unsafe.go @@ -12,12 +12,12 @@ import "unsafe" // Note that, if you completely sure you will never use `s` variable in the feature, // you can use this unsafe function to implement type conversion in high performance. func UnsafeStrToBytes(s string) []byte { - return *(*[]byte)(unsafe.Pointer(&s)) + return unsafe.Slice(unsafe.StringData(s), len(s)) } // UnsafeBytesToStr converts []byte to string without memory copy. // Note that, if you completely sure you will never use `b` variable in the feature, // you can use this unsafe function to implement type conversion in high performance. func UnsafeBytesToStr(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) }