summaryrefslogtreecommitdiff
path: root/test/wasm2js
diff options
context:
space:
mode:
authorjuj <jujjyl@gmail.com>2020-06-06 20:25:44 +0300
committerGitHub <noreply@github.com>2020-06-06 20:25:44 +0300
commit7fdec3735c712eb3588728c42bec4d34b82c5185 (patch)
tree1d04f37aaa811dc83f1e75b822afb5554b56a7bb /test/wasm2js
parent037d7a5d04c376b2fa8fc26076af9579c3712063 (diff)
downloadbinaryen-7fdec3735c712eb3588728c42bec4d34b82c5185.tar.gz
binaryen-7fdec3735c712eb3588728c42bec4d34b82c5185.tar.bz2
binaryen-7fdec3735c712eb3588728c42bec4d34b82c5185.zip
Micro-optimize base64Decode (#2897)
* Micro-optimize base64Decode * Update test expectations
Diffstat (limited to 'test/wasm2js')
-rw-r--r--test/wasm2js/dynamicLibrary.2asm.js12
-rw-r--r--test/wasm2js/dynamicLibrary.2asm.js.opt12
-rw-r--r--test/wasm2js/emscripten-grow-no.2asm.js12
-rw-r--r--test/wasm2js/emscripten-grow-no.2asm.js.opt12
-rw-r--r--test/wasm2js/emscripten-grow-yes.2asm.js12
-rw-r--r--test/wasm2js/emscripten-grow-yes.2asm.js.opt12
-rw-r--r--test/wasm2js/emscripten.2asm.js12
-rw-r--r--test/wasm2js/emscripten.2asm.js.opt12
8 files changed, 40 insertions, 56 deletions
diff --git a/test/wasm2js/dynamicLibrary.2asm.js b/test/wasm2js/dynamicLibrary.2asm.js
index 9666eb5ae..d9ae10cc6 100644
--- a/test/wasm2js/dynamicLibrary.2asm.js
+++ b/test/wasm2js/dynamicLibrary.2asm.js
@@ -59,15 +59,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(memasmFunc);
diff --git a/test/wasm2js/dynamicLibrary.2asm.js.opt b/test/wasm2js/dynamicLibrary.2asm.js.opt
index 28c547fb4..d2e28b645 100644
--- a/test/wasm2js/dynamicLibrary.2asm.js.opt
+++ b/test/wasm2js/dynamicLibrary.2asm.js.opt
@@ -51,15 +51,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(memasmFunc);
diff --git a/test/wasm2js/emscripten-grow-no.2asm.js b/test/wasm2js/emscripten-grow-no.2asm.js
index 71f229d2d..c3c0be859 100644
--- a/test/wasm2js/emscripten-grow-no.2asm.js
+++ b/test/wasm2js/emscripten-grow-no.2asm.js
@@ -55,15 +55,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(wasmMemory.buffer);
diff --git a/test/wasm2js/emscripten-grow-no.2asm.js.opt b/test/wasm2js/emscripten-grow-no.2asm.js.opt
index 71f229d2d..c3c0be859 100644
--- a/test/wasm2js/emscripten-grow-no.2asm.js.opt
+++ b/test/wasm2js/emscripten-grow-no.2asm.js.opt
@@ -55,15 +55,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(wasmMemory.buffer);
diff --git a/test/wasm2js/emscripten-grow-yes.2asm.js b/test/wasm2js/emscripten-grow-yes.2asm.js
index e927b7cf4..5d9b250cf 100644
--- a/test/wasm2js/emscripten-grow-yes.2asm.js
+++ b/test/wasm2js/emscripten-grow-yes.2asm.js
@@ -78,15 +78,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(wasmMemory.buffer);
diff --git a/test/wasm2js/emscripten-grow-yes.2asm.js.opt b/test/wasm2js/emscripten-grow-yes.2asm.js.opt
index e927b7cf4..5d9b250cf 100644
--- a/test/wasm2js/emscripten-grow-yes.2asm.js.opt
+++ b/test/wasm2js/emscripten-grow-yes.2asm.js.opt
@@ -78,15 +78,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(wasmMemory.buffer);
diff --git a/test/wasm2js/emscripten.2asm.js b/test/wasm2js/emscripten.2asm.js
index 444401fa4..cf9c0192e 100644
--- a/test/wasm2js/emscripten.2asm.js
+++ b/test/wasm2js/emscripten.2asm.js
@@ -213,15 +213,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(wasmMemory.buffer);
diff --git a/test/wasm2js/emscripten.2asm.js.opt b/test/wasm2js/emscripten.2asm.js.opt
index 77f060cb9..d0ed67fdb 100644
--- a/test/wasm2js/emscripten.2asm.js.opt
+++ b/test/wasm2js/emscripten.2asm.js.opt
@@ -194,15 +194,13 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i
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)];
}
}
var bufferView = new Uint8Array(wasmMemory.buffer);