-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge base64Decode.js and base64Utils.js into library_base64.js
The optimized base64Decode was only being using by minimal runtime. After this change it used in the regular runtime too which should speed up decoding.
- Loading branch information
Showing
13 changed files
with
89 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 The Emscripten Authors | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
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?) | ||
$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' | ||
} | ||
base64ReverseLookup[43] = 62; // '+' | ||
base64ReverseLookup[47] = 63; // '/' | ||
`, | ||
$base64Decode__docs: '/** @noinline */', | ||
$base64Decode: (b64) => { | ||
#if ENVIRONMENT_MAY_BE_NODE | ||
if (ENVIRONMENT_IS_NODE) { | ||
var buf = Buffer.from(b64, 'base64'); | ||
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength); | ||
} | ||
#endif | ||
|
||
#if ASSERTIONS | ||
assert(b64.length % 4 == 0); | ||
#endif | ||
var b1, b2, i = 0, j = 0, bLength = b64.length; | ||
var output = new Uint8Array((bLength*3>>2) - (b64[bLength-2] == '=') - (b64[bLength-1] == '=')); | ||
for (; i < bLength; i += 4, j += 3) { | ||
b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; | ||
b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; | ||
output[j] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; | ||
output[j+1] = b1 << 4 | b2 >> 2; | ||
output[j+2] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; | ||
} | ||
return output; | ||
}, | ||
|
||
// If filename is a base64 data URI, parses and returns data (Buffer on node, | ||
// Uint8Array otherwise). If filename is not a base64 data URI, returns | ||
// undefined. | ||
$tryParseAsDataURI: (filename) => { | ||
if (isDataURI(filename)) { | ||
return base64Decode(filename.slice(dataURIPrefix.length)); | ||
} | ||
}, | ||
|
||
$intArrayFromBase64: 'intArrayFromBase64', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"a.html": 12734, | ||
"a.html.gz": 6968, | ||
"total": 12734, | ||
"total_gz": 6968 | ||
"a.html": 12723, | ||
"a.html.gz": 6958, | ||
"total": 12723, | ||
"total_gz": 6958 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"a.html": 17275, | ||
"a.html.gz": 7537, | ||
"total": 17275, | ||
"total_gz": 7537 | ||
"a.html": 17371, | ||
"a.html.gz": 7580, | ||
"total": 17371, | ||
"total_gz": 7580 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters