mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
lib/fs: use unsafe.Slice instead of deprecated reflect.SliceHeader
This commit is contained in:
parent
4b1a262475
commit
9bc4c51ceb
@ -89,11 +89,7 @@ func mmap(fd int, length int) ([]byte, error) {
|
|||||||
windows.CloseHandle(h)
|
windows.CloseHandle(h)
|
||||||
return nil, os.NewSyscallError("MapViewOfFile", errno)
|
return nil, os.NewSyscallError("MapViewOfFile", errno)
|
||||||
}
|
}
|
||||||
data := make([]byte, 0)
|
data := unsafe.Slice(addr, length)
|
||||||
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
|
||||||
hdr.Data = addr
|
|
||||||
hdr.Len = length
|
|
||||||
hdr.Cap = hdr.Len
|
|
||||||
|
|
||||||
mmapByAddrLock.Lock()
|
mmapByAddrLock.Lock()
|
||||||
mmapByAddr[addr] = h
|
mmapByAddr[addr] = h
|
||||||
@ -105,8 +101,7 @@ func mmap(fd int, length int) ([]byte, error) {
|
|||||||
func mUnmap(data []byte) error {
|
func mUnmap(data []byte) error {
|
||||||
// flush is not needed, since we perform only reading operation.
|
// flush is not needed, since we perform only reading operation.
|
||||||
// In case of write, additional call FlushViewOfFile must be performed.
|
// In case of write, additional call FlushViewOfFile must be performed.
|
||||||
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
addr := uintptr(unsafe.Pointer(&data[0]))
|
||||||
addr := header.Data
|
|
||||||
|
|
||||||
mmapByAddrLock.Lock()
|
mmapByAddrLock.Lock()
|
||||||
h, ok := mmapByAddr[addr]
|
h, ok := mmapByAddr[addr]
|
||||||
|
Loading…
Reference in New Issue
Block a user