Skip to content

Commit bcebcc4

Browse files
yj-yooalanprot
authored andcommitted
change the reflect package to an unsafe package (cortexproject#5775)
Signed-off-by: Youngjun <[email protected]>
1 parent 9b9d68d commit bcebcc4

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

pkg/storage/tsdb/inmemory_index_cache.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tsdb
22

33
import (
44
"context"
5-
"reflect"
65
"unsafe"
76

87
"github.com/VictoriaMetrics/fastcache"
@@ -122,12 +121,7 @@ func yoloBuf(s string) []byte {
122121
}
123122

124123
func copyString(s string) string {
125-
var b []byte
126-
h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
127-
h.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
128-
h.Len = len(s)
129-
h.Cap = len(s)
130-
return string(b)
124+
return string(unsafe.Slice(unsafe.StringData(s), len(s)))
131125
}
132126

133127
// copyToKey is required as underlying strings might be memory-mapped.

0 commit comments

Comments
 (0)