Skip to content

Commit

Permalink
Fix new go 1.16 vet warning
Browse files Browse the repository at this point in the history
See golang/go#40701 and
alecthomas/unsafeslice#4 .

Feature-Start: go-1.16
  • Loading branch information
akalin committed Feb 21, 2021
1 parent 84b3444 commit b89ce31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions gf2p16/slice_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ func mulAndAddByteSliceLE(c T, in, out []byte, useSSSE3 bool) {
}

func castTToByteSlice(ts []T) []byte {
h := *(*reflect.SliceHeader)(unsafe.Pointer(&ts))
h.Len *= 2
h.Cap *= 2
return *(*[]byte)(unsafe.Pointer(&h))
tsHdr := (*reflect.SliceHeader)(unsafe.Pointer(&ts))
p := unsafe.Pointer(tsHdr.Data)

var bs []byte
bsHdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
bsHdr.Data = uintptr(p)
bsHdr.Len = 2 * tsHdr.Len
bsHdr.Cap = 2 * tsHdr.Cap
return bs
}

func mulSlice(c T, in, out []T) {
Expand Down
13 changes: 9 additions & 4 deletions gf2p16/slice_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import (
)

func castByteToTSlice(bs []byte) []T {
h := *(*reflect.SliceHeader)(unsafe.Pointer(&bs))
h.Len /= 2
h.Cap /= 2
return *(*[]T)(unsafe.Pointer(&h))
bsHdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
p := unsafe.Pointer(bsHdr.Data)

var ts []T
tsHdr := (*reflect.SliceHeader)(unsafe.Pointer(&ts))
tsHdr.Data = uintptr(p)
tsHdr.Len = bsHdr.Len / 2
tsHdr.Cap = bsHdr.Cap / 2
return ts
}

func mulByteSliceLEPlatformLE(c T, in, out []byte) {
Expand Down

0 comments on commit b89ce31

Please sign in to comment.