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 3d50366

Browse files
Improve array decoding performance
1 parent 6965305 commit 3d50366

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;
@@ -318,8 +319,9 @@ export class Decoder {
318319
// arrays and maps
319320
const state = stack[stack.length - 1];
320321
if (state.type === State.ARRAY) {
321-
state.array.push(object);
322-
if (state.array.length === state.size) {
322+
state.array[state.position] = object;
323+
state.position++;
324+
if (state.position === state.size) {
323325
stack.pop();
324326
object = state.array;
325327
} else {
@@ -387,7 +389,8 @@ export class Decoder {
387389
this.stack.push({
388390
type: State.ARRAY,
389391
size,
390-
array: [],
392+
array: new Array<unknown>(size),
393+
position: 0,
391394
});
392395
}
393396

0 commit comments

Comments
(0)

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