From da1d57e95d6354cefdbfc593a84888502331fcd2 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 30 Dec 2025 17:23:12 +0530 Subject: [PATCH] revert add --- core/vm/memory.go | 19 ++++++------------- core/vm/new_bench.txt | 7 ------- core/vm/old_bench.txt | 16 ---------------- 3 files changed, 6 insertions(+), 36 deletions(-) delete mode 100644 core/vm/new_bench.txt delete mode 100644 core/vm/old_bench.txt diff --git a/core/vm/memory.go b/core/vm/memory.go index a6bde15d6d..54bc2b2849 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -79,20 +79,13 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) { // Resize grows the memory to the requested size. func (m *Memory) Resize(size uint64) { - if size <= uint64(len(m.store)) { - return + if uint64(len(m.store)) < size { + if uint64(cap(m.store)) >= size { + 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 diff --git a/core/vm/new_bench.txt b/core/vm/new_bench.txt deleted file mode 100644 index 1cb4014e25..0000000000 --- a/core/vm/new_bench.txt +++ /dev/null @@ -1,7 +0,0 @@ -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 diff --git a/core/vm/old_bench.txt b/core/vm/old_bench.txt deleted file mode 100644 index 53c0eff049..0000000000 --- a/core/vm/old_bench.txt +++ /dev/null @@ -1,16 +0,0 @@ -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