diff --git a/src/Decoder.ts b/src/Decoder.ts index 84c4caa2..8cfb3879 100644 --- a/src/Decoder.ts +++ b/src/Decoder.ts @@ -23,6 +23,7 @@ type StackArrayState = { type: State.ARRAY; size: number; array: Array; + position: number; }; type StackState = StackArrayState | StackMapState; @@ -318,8 +319,9 @@ export class Decoder { // arrays and maps const state = stack[stack.length - 1]; if (state.type === State.ARRAY) { - state.array.push(object); - if (state.array.length === state.size) { + state.array[state.position] = object; + state.position++; + if (state.position === state.size) { stack.pop(); object = state.array; } else { @@ -387,7 +389,8 @@ export class Decoder { this.stack.push({ type: State.ARRAY, size, - array: [], + array: new Array(size), + position: 0, }); }