mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/mergeset: use unsafe.Slice and unsafe.String instead of deprecated reflect.SliceHeader with unsafe conversion from slice header to string header
This commit is contained in:
parent
38e0397ebd
commit
6a8dc74ee7
1 changed files with 3 additions and 10 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -29,21 +28,15 @@ type Item struct {
|
|||
// The returned bytes representation belongs to data.
|
||||
func (it Item) Bytes(data []byte) []byte {
|
||||
n := int(it.End - it.Start)
|
||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
||||
sh.Cap = n
|
||||
sh.Len = n
|
||||
sh.Data += uintptr(it.Start)
|
||||
return data
|
||||
return unsafe.Slice((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(unsafe.SliceData(data)))+uintptr(it.Start))), n)
|
||||
}
|
||||
|
||||
// String returns string representation of it obtained from data.
|
||||
//
|
||||
// The returned string representation belongs to data.
|
||||
func (it Item) String(data []byte) string {
|
||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
||||
sh.Data += uintptr(it.Start)
|
||||
sh.Len = int(it.End - it.Start)
|
||||
return *(*string)(unsafe.Pointer(sh))
|
||||
n := int(it.End - it.Start)
|
||||
return unsafe.String((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(unsafe.SliceData(data)))+uintptr(it.Start))), n)
|
||||
}
|
||||
|
||||
func (ib *inmemoryBlock) Len() int {
|
||||
|
|
Loading…
Reference in a new issue