Merge pull request #1414 from RReverser/smaller-realloc

Optimise encodeInto reallocations
This commit is contained in:
Alex Crichton 2019-04-02 10:26:03 -05:00 committed by GitHub
commit a1c457bd15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;