Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2589c87

Browse files
authored
Merge pull request #32 from sergeyzenchenko/master
Improve array decoding performance
2 parents 1dd1d7d + 3d50366 commit 2589c87

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎src/Decoder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type StackArrayState = {
2323
type: State.ARRAY;
2424
size: number;
2525
array: Array<unknown>;
26+
position: number;
2627
};
2728

2829
type StackState = StackArrayState | StackMapState;
@@ -314,8 +315,9 @@ export class Decoder {
314315
// arrays and maps
315316
const state = stack[stack.length - 1];
316317
if (state.type === State.ARRAY) {
317-
state.array.push(object);
318-
if (state.array.length === state.size) {
318+
state.array[state.position] = object;
319+
state.position++;
320+
if (state.position === state.size) {
319321
stack.pop();
320322
object = state.array;
321323
} else {
@@ -383,7 +385,8 @@ export class Decoder {
383385
this.stack.push({
384386
type: State.ARRAY,
385387
size,
386-
array: [],
388+
array: new Array<unknown>(size),
389+
position: 0,
387390
});
388391
}
389392

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /