Skip to content

Commit

Permalink
Merge pull request #1414 from RReverser/smaller-realloc
Browse files Browse the repository at this point in the history
Optimise encodeInto reallocations
  • Loading branch information
alexcrichton authored Apr 2, 2019
2 parents f367a42 + 2f28b8b commit a1c457b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,13 +1306,12 @@ impl<'a> Context<'a> {
while (true) {{
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size);
const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view);
arg = arg.substring(read);
writeOffset += written;
if (arg.length === 0) {{
if (read === arg.length) {{
break;
}}
ptr = wasm.__wbindgen_realloc(ptr, size, size * 2);
size *= 2;
arg = arg.substring(read);
writeOffset += written;
ptr = wasm.__wbindgen_realloc(ptr, size, size += arg.length * 3);
}}
WASM_VECTOR_LEN = writeOffset;
return ptr;
Expand Down

0 comments on commit a1c457b

Please sign in to comment.