mirror of
https://github.com/golang/go
synced 2024-10-04 15:09:59 +00:00
syscall: use unsafe.Slice instead of unsafeheader package
Change-Id: I9de5aafb36d05bdc90bbdba516367eb2b200a7e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/428777 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
1b196988d4
commit
f53b2111e4
|
@ -11,7 +11,6 @@ import (
|
|||
"internal/itoa"
|
||||
"internal/oserror"
|
||||
"internal/race"
|
||||
"internal/unsafeheader"
|
||||
"runtime"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
@ -57,11 +56,7 @@ func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (d
|
|||
}
|
||||
|
||||
// Use unsafe to turn addr into a []byte.
|
||||
var b []byte
|
||||
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
|
||||
hdr.Data = unsafe.Pointer(addr)
|
||||
hdr.Cap = length
|
||||
hdr.Len = length
|
||||
b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), length)
|
||||
|
||||
// Register mapping in m and return it.
|
||||
p := &b[cap(b)-1]
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"internal/itoa"
|
||||
"internal/oserror"
|
||||
"internal/race"
|
||||
"internal/unsafeheader"
|
||||
"runtime"
|
||||
"sync"
|
||||
"unicode/utf16"
|
||||
|
@ -78,11 +77,7 @@ func utf16PtrToString(p *uint16) string {
|
|||
n++
|
||||
}
|
||||
// Turn *uint16 into []uint16.
|
||||
var s []uint16
|
||||
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&s))
|
||||
hdr.Data = unsafe.Pointer(p)
|
||||
hdr.Cap = n
|
||||
hdr.Len = n
|
||||
s := unsafe.Slice((*uint16)(unsafe.Pointer(p)), n)
|
||||
// Decode []uint16 into string.
|
||||
return string(utf16.Decode(s))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue