From 7d9ed98019cb3995aacbc49dbae8e17127b17057 Mon Sep 17 00:00:00 2001 From: Qian Bin Date: Wed, 11 May 2022 17:00:29 +0800 Subject: [PATCH] core/vm: optimize Memory.Set32 (#24847) * core/vm: remove unnecessary memset for Memory.Set32 * core/vm: optimize Memory.Set32 --- core/vm/memory.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/vm/memory.go b/core/vm/memory.go index 7db2308187bf..35b729996075 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -53,10 +53,9 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) { if offset+32 > uint64(len(m.store)) { panic("invalid memory: store empty") } - // Zero the memory area - copy(m.store[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) // Fill in relevant bits - val.WriteToSlice(m.store[offset:]) + b32 := val.Bytes32() + copy(m.store[offset:], b32[:]) } // Resize resizes the memory to size