Skip to content

Commit 6504538

Browse files
authored
update utils.go to use simpler, yet still safe, cast
1 parent d52f648 commit 6504538

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

utils.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"io"
77
"reflect"
8-
"runtime"
98
"strconv"
109
"strings"
1110
"time"
@@ -256,13 +255,11 @@ func strCmp(s1, s2 string) int {
256255
}
257256
}
258257

259-
func unsafeFastStringToReadOnlyBytes(s string) []byte {
260-
b := make([]byte, 0)
258+
func unsafeFastStringToReadOnlyBytes(s string) (bs []byte) {
261259
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
262-
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
260+
bh := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
263261
bh.Data = sh.Data
264262
bh.Cap = sh.Len
265263
bh.Len = sh.Len
266-
runtime.KeepAlive(s)
267-
return b
264+
return
268265
}

0 commit comments

Comments
 (0)