Skip to content

Commit d61861c

Browse files
committed
feat: optimize atob and btoa performance
1 parent fa65a68 commit d61861c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/core-js/modules/web.atob.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $({ global: true, bind: true, enumerable: true, forced: FORCED }, {
4747
// `webpack` dev server bug on IE global methods - use call(fn, global, ...)
4848
if (BASIC && !NO_SPACES_IGNORE && !NO_ENCODING_CHECK) return call($atob, globalThis, data);
4949
var string = replace(toString(data), whitespaces, '');
50-
var output = '';
50+
var output = [];
5151
var position = 0;
5252
var bc = 0;
5353
var length, chr, bs;
@@ -61,7 +61,7 @@ $({ global: true, bind: true, enumerable: true, forced: FORCED }, {
6161
while (position < length) {
6262
chr = charAt(string, position++);
6363
bs = bc % 4 ? bs * 64 + c2i[chr] : c2i[chr];
64-
if (bc++ % 4) output += fromCharCode(255 & bs >> (-2 * bc & 6));
65-
} return output;
64+
if (bc++ % 4) output.push(fromCharCode(255 & bs >> (-2 * bc & 6)));
65+
} return output.join('');
6666
}
6767
});

packages/core-js/modules/web.btoa.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $({ global: true, bind: true, enumerable: true, forced: !BASIC || NO_ARG_RECEIVI
3535
// `webpack` dev server bug on IE global methods - use call(fn, global, ...)
3636
if (BASIC) return call($btoa, globalThis, toString(data));
3737
var string = toString(data);
38-
var output = '';
38+
var output = [];
3939
var position = 0;
4040
var map = i2c;
4141
var block, charCode;
@@ -45,7 +45,7 @@ $({ global: true, bind: true, enumerable: true, forced: !BASIC || NO_ARG_RECEIVI
4545
throw new (getBuiltIn('DOMException'))('The string contains characters outside of the Latin1 range', 'InvalidCharacterError');
4646
}
4747
block = block << 8 | charCode;
48-
output += charAt(map, 63 & block >> 8 - position % 1 * 8);
49-
} return output;
48+
output.push(charAt(map, 63 & block >> 8 - position % 1 * 8));
49+
} return output.join('');
5050
}
5151
});

0 commit comments

Comments
 (0)