Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint issue SA1019 reflect.SliceHeader #637

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions consensus/ethash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/binary"
"hash"
"math/big"
"reflect"
"runtime"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -176,12 +175,7 @@ func generateCache(dest []uint32, epoch uint64, epochLength uint64, seed []byte)
logFn("Generated ethash verification cache", "epochLength", epochLength, "elapsed", common.PrettyDuration(elapsed))
}()
// Convert our destination slice to a byte buffer
var cache []byte
cacheHdr := (*reflect.SliceHeader)(unsafe.Pointer(&cache))
dstHdr := (*reflect.SliceHeader)(unsafe.Pointer(&dest))
cacheHdr.Data = dstHdr.Data
cacheHdr.Len = dstHdr.Len * 4
cacheHdr.Cap = dstHdr.Cap * 4
cache := unsafe.Slice((*byte)(unsafe.Pointer(&dest[0])), len(dest)*4)

// Calculate the number of theoretical rows (we'll store in one buffer nonetheless)
size := uint64(len(cache))
Expand Down Expand Up @@ -310,12 +304,7 @@ func generateDataset(dest []uint32, epoch uint64, epochLength uint64, cache []ui
swapped := !isLittleEndian()

// Convert our destination slice to a byte buffer
var dataset []byte
datasetHdr := (*reflect.SliceHeader)(unsafe.Pointer(&dataset))
destHdr := (*reflect.SliceHeader)(unsafe.Pointer(&dest))
datasetHdr.Data = destHdr.Data
datasetHdr.Len = destHdr.Len * 4
datasetHdr.Cap = destHdr.Cap * 4
dataset := unsafe.Slice((*byte)(unsafe.Pointer(&dest[0])), len(dest)*4)

// Generate the dataset on many goroutines since it takes a while
threads := runtime.NumCPU()
Expand Down
7 changes: 1 addition & 6 deletions consensus/ethash/ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"math/rand"
"os"
"path/filepath"
"reflect"
"runtime"
"strconv"
"sync"
Expand Down Expand Up @@ -144,11 +143,7 @@ func memoryMapFile(file *os.File, write bool) (mmap.MMap, []uint32, error) {
return nil, nil, err
}
// The file is now memory-mapped. Create a []uint32 view of the file.
var view []uint32
header := (*reflect.SliceHeader)(unsafe.Pointer(&view))
header.Data = (*reflect.SliceHeader)(unsafe.Pointer(&mem)).Data
header.Cap = len(mem) / 4
header.Len = header.Cap
view := unsafe.Slice((*uint32)(unsafe.Pointer(&mem[0])), len(mem)/4)
return mem, view, nil
}

Expand Down
Loading