mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 05:16:35 +08:00
Merge 8c235252b6c626d755144a5e3b029cf65e83caf1 into 80cd679c43a3d6ed03957b6a3614f97d0af0751c
This commit is contained in:
commit
d1dcaf4ea4
@ -4,21 +4,12 @@
|
||||
|
||||
package bytesconv
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// StringToBytes converts string to byte slice without a memory allocation.
|
||||
// StringToBytes converts string to byte slice
|
||||
func StringToBytes(s string) []byte {
|
||||
return *(*[]byte)(unsafe.Pointer(
|
||||
&struct {
|
||||
string
|
||||
Cap int
|
||||
}{s, len(s)},
|
||||
))
|
||||
return []byte(s)
|
||||
}
|
||||
|
||||
// BytesToString converts byte slice to string without a memory allocation.
|
||||
// BytesToString converts byte slice to string
|
||||
func BytesToString(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
return string(b)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user