Skip to content

Commit 4fa1ba8

Browse files
committed
Replace go1.17 unsafe.Slice with go1.16 compatible code.
1 parent 82aec37 commit 4fa1ba8

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/tunabay/go-bitarray
22

3-
go 1.17
3+
go 1.16
44

55
require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

util.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package bitarray
66

77
import (
88
"fmt"
9+
"reflect"
910
"unsafe"
1011
)
1112

@@ -345,14 +346,14 @@ func allocByteSlice(nBytes int) []byte {
345346
func asUint64Slice(b []byte) []uint64 {
346347
// s := (*[cap(b)>>3]uint64)(unsafe.Pointer(&b[0]))[:]
347348

348-
// n := (len(b) + 7) >> 3
349-
// s := make([]uint64, 0)
350-
// h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
351-
// h.Data, h.Len, h.Cap = uintptr(unsafe.Pointer(&b[0])), n, n
349+
n := (len(b) + 7) >> 3
350+
s := make([]uint64, 0)
351+
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
352+
h.Data, h.Len, h.Cap = uintptr(unsafe.Pointer(&b[0])), n, n
352353

353354
// Since go1.17
354-
//nolint:typecheck // 2021-08-21: v1.42.0 does not support go1.17?
355-
s := unsafe.Slice((*uint64)(unsafe.Pointer(&b[0])), (len(b)+7)>>3)
355+
// 2021-08-21: golangcilint v1.42.0 does not support go1.17?
356+
// s := unsafe.Slice((*uint64)(unsafe.Pointer(&b[0])), (len(b)+7)>>3)
356357

357358
return s
358359
}

0 commit comments

Comments
 (0)