|
@@ -288,11 +288,12 @@ func NoEscape(p unsafe.Pointer) unsafe.Pointer {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func UnsafeCastString(str string) []byte {
|
|
func UnsafeCastString(str string) []byte {
|
|
|
|
|
+ bytes := make([]byte, 0)
|
|
|
stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
|
- sliceHeader := &reflect.SliceHeader{
|
|
|
|
|
- Data: stringHeader.Data,
|
|
|
|
|
- Cap: stringHeader.Len,
|
|
|
|
|
- Len: stringHeader.Len,
|
|
|
|
|
- }
|
|
|
|
|
- return *(*[]byte)(unsafe.Pointer(sliceHeader))
|
|
|
|
|
|
|
+ sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
|
|
|
|
|
+ sliceHeader.Data = stringHeader.Data
|
|
|
|
|
+ sliceHeader.Cap = stringHeader.Len
|
|
|
|
|
+ sliceHeader.Len = stringHeader.Len
|
|
|
|
|
+ runtime.KeepAlive(str)
|
|
|
|
|
+ return bytes
|
|
|
}
|
|
}
|