|
14 | 14 | using System.Linq; |
15 | 15 | using System.Numerics; |
16 | 16 | using System.Runtime.CompilerServices; |
| 17 | +using Array = System.Array; |
17 | 18 | using VMArray = Neo.VM.Types.Array; |
18 | 19 |
|
19 | 20 | namespace Neo.VM |
@@ -151,8 +152,9 @@ public virtual void NewArray(ExecutionEngine engine, Instruction instruction) |
151 | 152 | var n = (int)engine.Pop().GetInteger(); |
152 | 153 | if (n < 0 || n > engine.Limits.MaxStackSize) |
153 | 154 | throw new InvalidOperationException($"MaxStackSize exceed: {n}"); |
154 | | - |
155 | | - engine.Push(new VMArray(engine.ReferenceCounter, Enumerable.Repeat(StackItem.Null, n))); |
| 155 | + var nullArray = new StackItem[n]; |
| 156 | + Array.Fill(nullArray, StackItem.Null); |
| 157 | + engine.Push(new VMArray(engine.ReferenceCounter, nullArray)); |
156 | 158 | } |
157 | 159 |
|
158 | 160 | /// <summary> |
@@ -180,8 +182,9 @@ public virtual void NewArray_T(ExecutionEngine engine, Instruction instruction) |
180 | 182 | (byte)StackItemType.ByteString => ByteString.Empty, |
181 | 183 | _ => StackItem.Null |
182 | 184 | }; |
183 | | - |
184 | | - engine.Push(new VMArray(engine.ReferenceCounter, Enumerable.Repeat(item, n))); |
| 185 | + var itemArray = new StackItem[n]; |
| 186 | + Array.Fill(itemArray, item); |
| 187 | + engine.Push(new VMArray(engine.ReferenceCounter, itemArray)); |
185 | 188 | } |
186 | 189 |
|
187 | 190 | /// <summary> |
@@ -210,10 +213,10 @@ public virtual void NewStruct(ExecutionEngine engine, Instruction instruction) |
210 | 213 | var n = (int)engine.Pop().GetInteger(); |
211 | 214 | if (n < 0 || n > engine.Limits.MaxStackSize) |
212 | 215 | throw new InvalidOperationException($"MaxStackSize exceed: {n}"); |
213 | | - Struct result = new(engine.ReferenceCounter); |
214 | | - for (var i = 0; i < n; i++) |
215 | | - result.Add(StackItem.Null); |
216 | | - engine.Push(result); |
| 216 | + |
| 217 | + var nullArray = new StackItem[n]; |
| 218 | + Array.Fill(nullArray, StackItem.Null); |
| 219 | + engine.Push(new Struct(engine.ReferenceCounter, nullArray)); |
217 | 220 | } |
218 | 221 |
|
219 | 222 | /// <summary> |
|
0 commit comments