mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +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) {{
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user