diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm2js.h | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h index 9d3fdd0ec..a904bd0f9 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -2258,15 +2258,13 @@ void Wasm2JSGlue::emitMemory( base64ReverseLookup[47] = 63; // '/' /** @noinline Inlining this function would mean expanding the base64 string 4x times in the source code, which Closure seems to be happy to do. */ function base64DecodeToExistingUint8Array(uint8Array, offset, b64) { - var b1, b2, i = 0, j = offset, bLength = b64.length, end = offset + (bLength*3>>2); - if (b64[bLength-2] == '=') --end; - if (b64[bLength-1] == '=') --end; - for (; i < bLength; i += 4, j += 3) { + var b1, b2, i = 0, j = offset, bLength = b64.length, end = offset + (bLength*3>>2) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j+1 < end) uint8Array[j+1] = b1 << 4 | b2 >> 2; - if (j+2 < end) uint8Array[j+2] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; } })"; out << expr << '\n'; |