diff --git a/src/lib/libbase64.js b/src/lib/libbase64.js index 48546622878f1..3f0739e9d155c 100644 --- a/src/lib/libbase64.js +++ b/src/lib/libbase64.js @@ -8,18 +8,20 @@ addToLibrary({ // Decodes a _known valid_ base64 string (without validation) and returns it as a new Uint8Array. // Benchmarked to be around 5x faster compared to a simple // "Uint8Array.from(atob(b64), c => c.charCodeAt(0))" (TODO: perhaps use this form in -Oz builds?) +#if !JS_BASE64_API $base64Decode__postset: ` // Precreate a reverse lookup table from chars // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" back to // bytes to make decoding fast. - for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i) { - base64ReverseLookup[48+i] = 52+i; // '0-9' - base64ReverseLookup[65+i] = i; // 'A-Z' - base64ReverseLookup[97+i] = 26+i; // 'a-z' + for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), __b64i = 25; __b64i >= 0; --__b64i) { + base64ReverseLookup[48+__b64i] = 52+__b64i; // '0-9' + base64ReverseLookup[65+__b64i] = __b64i; // 'A-Z' + base64ReverseLookup[97+__b64i] = 26+__b64i; // 'a-z' } base64ReverseLookup[43] = 62; // '+' base64ReverseLookup[47] = 63; // '/' `, +#endif $base64Decode__docs: '/** @noinline */', $base64Decode: (b64) => { #if JS_BASE64_API diff --git a/test/codesize/test_codesize_hello_single_file.json b/test/codesize/test_codesize_hello_single_file.json index 531826ef78b44..44dea2cde8813 100644 --- a/test/codesize/test_codesize_hello_single_file.json +++ b/test/codesize/test_codesize_hello_single_file.json @@ -1,6 +1,6 @@ { - "a.out.js": 5371, - "a.out.js.gz": 2984, + "a.out.js": 5273, + "a.out.js.gz": 2921, "sent": [ "a (fd_write)" ] diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json index 819c402815ee8..3d2402f8aff1b 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json @@ -1,4 +1,4 @@ { - "a.html": 15140, - "a.html.gz": 9079 + "a.html": 15046, + "a.html.gz": 9018 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json index 61f7f42ba4aff..41ce4cfdd5704 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json @@ -1,4 +1,4 @@ { - "a.html": 10982, - "a.html.gz": 5743 + "a.html": 10884, + "a.html.gz": 5674 } diff --git a/tools/link.py b/tools/link.py index 4303f257ea9dc..54f44551cfed7 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1957,7 +1957,7 @@ def phase_emscript(in_wasm, wasm_target, js_syms, base_metadata): # No need to support base64 embedding in wasm2js mode since # the module is already in JS format. - if settings.SINGLE_FILE and not settings.WASM2JS: + if settings.SINGLE_FILE and not settings.SINGLE_FILE_BINARY_ENCODE and not settings.WASM2JS: settings.SUPPORT_BASE64_EMBEDDING = 1 settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$base64Decode')