Skip to content

Commit 6c5c801

Browse files
committed
avoid allocating an array
1 parent d7fa0aa commit 6c5c801

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/stringify.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,21 @@ export function stringify(value) {
7777
break;
7878

7979
case 'Array':
80-
/** @type {number[]} */
81-
let flattened_array = [];
80+
str = '[';
8281

8382
for (let i = 0; i < thing.length; i += 1) {
83+
if (i > 0) str += ',';
84+
8485
if (i in thing) {
8586
keys.push(`[${i}]`);
86-
flattened_array.push(flatten(thing[i]));
87+
str += flatten(thing[i]);
8788
keys.pop();
8889
} else {
89-
flattened_array.push(HOLE);
90+
str += HOLE;
9091
}
9192
}
9293

93-
str = `[${flattened_array.join(',')}]`;
94+
str += ']';
9495

9596
break;
9697

0 commit comments

Comments
 (0)