mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-18 05:56:37 +00:00
add
This commit is contained in:
parent
41ebaf0ff2
commit
a389dbd802
3 changed files with 36 additions and 6 deletions
|
|
@ -79,13 +79,20 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) {
|
||||||
|
|
||||||
// Resize grows the memory to the requested size.
|
// Resize grows the memory to the requested size.
|
||||||
func (m *Memory) Resize(size uint64) {
|
func (m *Memory) Resize(size uint64) {
|
||||||
if uint64(len(m.store)) < size {
|
if size <= uint64(len(m.store)) {
|
||||||
if uint64(cap(m.store)) >= size {
|
return
|
||||||
m.store = m.store[:size]
|
|
||||||
} else {
|
|
||||||
m.store = append(m.store, make([]byte, size-uint64(len(m.store)))...)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if size <= uint64(cap(m.store)) {
|
||||||
|
prevLen := len(m.store)
|
||||||
|
m.store = m.store[:size]
|
||||||
|
clear(m.store[prevLen:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
store := make([]byte, size)
|
||||||
|
copy(store, m.store)
|
||||||
|
m.store = store
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCopy returns offset + size as a new slice
|
// GetCopy returns offset + size as a new slice
|
||||||
|
|
|
||||||
7
core/vm/new_bench.txt
Normal file
7
core/vm/new_bench.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
pkg: github.com/ethereum/go-ethereum/core/vm
|
||||||
|
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
|
||||||
|
BenchmarkResize-8 876326 89800 ns/op 442142 B/op 1 allocs/op
|
||||||
|
BenchmarkResize-8 signal: interrupt
|
||||||
|
FAIL github.com/ethereum/go-ethereum/core/vm 154.281s
|
||||||
16
core/vm/old_bench.txt
Normal file
16
core/vm/old_bench.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
pkg: github.com/ethereum/go-ethereum/core/vm
|
||||||
|
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
|
||||||
|
BenchmarkResize-8 513681400 4.756 ns/op 5 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 747650196 2.313 ns/op 6 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 907757728 1.302 ns/op 5 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 906696679 1.356 ns/op 5 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 832139062 2.823 ns/op 5 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 943258486 2.120 ns/op 6 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 1000000000 1.619 ns/op 5 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 982619973 1.388 ns/op 5 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 761129438 1.351 ns/op 6 B/op 0 allocs/op
|
||||||
|
BenchmarkResize-8 943591894 1.643 ns/op 6 B/op 0 allocs/op
|
||||||
|
PASS
|
||||||
|
ok github.com/ethereum/go-ethereum/core/vm 37.469s
|
||||||
Loading…
Reference in a new issue