Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/Neo.VM/JumpTable/JumpTable.Compound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using Array = System.Array;
using VMArray = Neo.VM.Types.Array;

namespace Neo.VM
Expand Down Expand Up @@ -151,8 +152,9 @@ public virtual void NewArray(ExecutionEngine engine, Instruction instruction)
var n = (int)engine.Pop().GetInteger();
if (n < 0 || n > engine.Limits.MaxStackSize)
throw new InvalidOperationException($"MaxStackSize exceed: {n}");

engine.Push(new VMArray(engine.ReferenceCounter, Enumerable.Repeat(StackItem.Null, n)));
var nullArray = new StackItem[n];
Array.Fill(nullArray, StackItem.Null);
engine.Push(new VMArray(engine.ReferenceCounter, nullArray));
}

/// <summary>
Expand Down Expand Up @@ -180,8 +182,9 @@ public virtual void NewArray_T(ExecutionEngine engine, Instruction instruction)
(byte)StackItemType.ByteString => ByteString.Empty,
_ => StackItem.Null
};

engine.Push(new VMArray(engine.ReferenceCounter, Enumerable.Repeat(item, n)));
var itemArray = new StackItem[n];
Array.Fill(itemArray, item);
engine.Push(new VMArray(engine.ReferenceCounter, itemArray));
}

/// <summary>
Expand Down Expand Up @@ -210,10 +213,10 @@ public virtual void NewStruct(ExecutionEngine engine, Instruction instruction)
var n = (int)engine.Pop().GetInteger();
if (n < 0 || n > engine.Limits.MaxStackSize)
throw new InvalidOperationException($"MaxStackSize exceed: {n}");
Struct result = new(engine.ReferenceCounter);
for (var i = 0; i < n; i++)
result.Add(StackItem.Null);
engine.Push(result);

var nullArray = new StackItem[n];
Array.Fill(nullArray, StackItem.Null);
engine.Push(new Struct(engine.ReferenceCounter, nullArray));
}

/// <summary>
Expand Down
Loading