1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-25 00:01:00 +03:00

Speedup ScanSlice

This commit is contained in:
Vladimir Mihailenco
2017-06-02 16:19:43 +03:00
parent 3802e09b42
commit f29951c899
3 changed files with 19 additions and 2 deletions

View File

@@ -9,6 +9,19 @@ import (
func BytesToString(b []byte) string {
bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
strHeader := reflect.StringHeader{bytesHeader.Data, bytesHeader.Len}
strHeader := reflect.StringHeader{
Data: bytesHeader.Data,
Len: bytesHeader.Len,
}
return *(*string)(unsafe.Pointer(&strHeader))
}
func StringToBytes(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh := reflect.SliceHeader{
Data: sh.Data,
Len: sh.Len,
Cap: sh.Len,
}
return *(*[]byte)(unsafe.Pointer(&bh))
}