Skip to content

Commit a1c457b

Browse files
authored
Merge pull request #1414 from RReverser/smaller-realloc
Optimise encodeInto reallocations
2 parents f367a42 + 2f28b8b commit a1c457b

File tree

1 file changed

+4
-5
lines changed
  • crates/cli-support/src/js

1 file changed

+4
-5
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,13 +1306,12 @@ impl<'a> Context<'a> {
13061306
while (true) {{
13071307
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size);
13081308
const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view);
1309-
arg = arg.substring(read);
1310-
writeOffset += written;
1311-
if (arg.length === 0) {{
1309+
if (read === arg.length) {{
13121310
break;
13131311
}}
1314-
ptr = wasm.__wbindgen_realloc(ptr, size, size * 2);
1315-
size *= 2;
1312+
arg = arg.substring(read);
1313+
writeOffset += written;
1314+
ptr = wasm.__wbindgen_realloc(ptr, size, size += arg.length * 3);
13161315
}}
13171316
WASM_VECTOR_LEN = writeOffset;
13181317
return ptr;

0 commit comments

Comments
 (0)