mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-21 12:12:13 +00:00
Merge pull request #1414 from RReverser/smaller-realloc
Optimise encodeInto reallocations
This commit is contained in:
commit
a1c457bd15
@ -1306,13 +1306,12 @@ impl<'a> Context<'a> {
|
|||||||
while (true) {{
|
while (true) {{
|
||||||
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size);
|
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size);
|
||||||
const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view);
|
const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view);
|
||||||
arg = arg.substring(read);
|
if (read === arg.length) {{
|
||||||
writeOffset += written;
|
|
||||||
if (arg.length === 0) {{
|
|
||||||
break;
|
break;
|
||||||
}}
|
}}
|
||||||
ptr = wasm.__wbindgen_realloc(ptr, size, size * 2);
|
arg = arg.substring(read);
|
||||||
size *= 2;
|
writeOffset += written;
|
||||||
|
ptr = wasm.__wbindgen_realloc(ptr, size, size += arg.length * 3);
|
||||||
}}
|
}}
|
||||||
WASM_VECTOR_LEN = writeOffset;
|
WASM_VECTOR_LEN = writeOffset;
|
||||||
return ptr;
|
return ptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user