Skip to content

Commit

Permalink
change the reflect package to an unsafe package (#5775)
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjun <yj.yoo@okestro.com>
  • Loading branch information
yj-yoo authored Mar 30, 2024
1 parent 65d218b commit c2eb4e7
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/storage/tsdb/inmemory_index_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tsdb

import (
"context"
"reflect"
"unsafe"

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

func copyString(s string) string {
var b []byte
h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
h.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
h.Len = len(s)
h.Cap = len(s)
return string(b)
return string(unsafe.Slice(unsafe.StringData(s), len(s)))
}

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

0 comments on commit c2eb4e7

Please sign in to comment.