From f02d8b4ec4c3fd38e31994c2c1af8957e145c058 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 3 Aug 2021 16:29:21 +0300 Subject: [PATCH] stackitem: serialize integers to the pre-allocated slice Signed-off-by: Evgeniy Stratonikov --- pkg/vm/stackitem/serialization.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/vm/stackitem/serialization.go b/pkg/vm/stackitem/serialization.go index b9a814e46..84e01bedc 100644 --- a/pkg/vm/stackitem/serialization.go +++ b/pkg/vm/stackitem/serialization.go @@ -112,8 +112,11 @@ func (w *serContext) serialize(item Item) error { } case *BigInteger: w.data = append(w.data, byte(IntegerT)) - data := bigint.ToBytes(t.Value().(*big.Int)) - w.appendVarUint(uint64(len(data))) + v := t.Value().(*big.Int) + ln := len(w.data) + w.data = append(w.data, 0) + data := bigint.ToPreallocatedBytes(v, w.data[len(w.data):]) + w.data[ln] = byte(len(data)) w.data = append(w.data, data...) case *Interop: if w.allowInvalid {