This commit is contained in:
源文雨
2024-10-13 19:43:12 +09:00
parent efbd9f6b20
commit 62c237674f
6 changed files with 295 additions and 0 deletions

15
helper.go Normal file
View File

@@ -0,0 +1,15 @@
package fumitok
import (
"unsafe"
)
// BytesToString 没有内存开销的转换
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// StringToBytes 没有内存开销的转换
func StringToBytes(s string) (b []byte) {
return unsafe.Slice(unsafe.StringData(s), len(s))
}