mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-30 15:22:07 +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
99269ea640
commit
01d8bee14c
1 changed files with 3 additions and 10 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -29,21 +28,15 @@ type Item struct {
|
||||||
// The returned bytes representation belongs to data.
|
// The returned bytes representation belongs to data.
|
||||||
func (it Item) Bytes(data []byte) []byte {
|
func (it Item) Bytes(data []byte) []byte {
|
||||||
n := int(it.End - it.Start)
|
n := int(it.End - it.Start)
|
||||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
return unsafe.Slice((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(unsafe.SliceData(data)))+uintptr(it.Start))), n)
|
||||||
sh.Cap = n
|
|
||||||
sh.Len = n
|
|
||||||
sh.Data += uintptr(it.Start)
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns string representation of it obtained from data.
|
// String returns string representation of it obtained from data.
|
||||||
//
|
//
|
||||||
// The returned string representation belongs to data.
|
// The returned string representation belongs to data.
|
||||||
func (it Item) String(data []byte) string {
|
func (it Item) String(data []byte) string {
|
||||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
n := int(it.End - it.Start)
|
||||||
sh.Data += uintptr(it.Start)
|
return unsafe.String((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(unsafe.SliceData(data)))+uintptr(it.Start))), n)
|
||||||
sh.Len = int(it.End - it.Start)
|
|
||||||
return *(*string)(unsafe.Pointer(sh))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ib *inmemoryBlock) Len() int {
|
func (ib *inmemoryBlock) Len() int {
|
||||||
|
|
Loading…
Reference in a new issue