diff --git a/consensus/ethash/algorithm.go b/consensus/ethash/algorithm.go index 77af64dc70..4a3a397216 100644 --- a/consensus/ethash/algorithm.go +++ b/consensus/ethash/algorithm.go @@ -20,7 +20,6 @@ import ( "encoding/binary" "hash" "math/big" - "reflect" "runtime" "sync" "sync/atomic" @@ -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)) @@ -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() diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 8258aaa225..978e6eeb2e 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -26,7 +26,6 @@ import ( "math/rand" "os" "path/filepath" - "reflect" "runtime" "strconv" "sync" @@ -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 }