Skip to content

Commit 9be5d63

Browse files
committed
feat: pre-allocating array
1 parent d61861c commit 9be5d63

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
var $ = require('../internals/export');
3+
var arrayFrom = require('../internals/array-from');
34
var globalThis = require('../internals/global-this');
45
var getBuiltIn = require('../internals/get-built-in');
56
var uncurryThis = require('../internals/function-uncurry-this');
@@ -47,7 +48,8 @@ $({ global: true, bind: true, enumerable: true, forced: FORCED }, {
4748
// `webpack` dev server bug on IE global methods - use call(fn, global, ...)
4849
if (BASIC && !NO_SPACES_IGNORE && !NO_ENCODING_CHECK) return call($atob, globalThis, data);
4950
var string = replace(toString(data), whitespaces, '');
50-
var output = [];
51+
// every 4 characters produce 3 bytes, so ceil(length * 3 / 4) is the number of bytes
52+
var output = arrayFrom({ length: Math.ceil(string.length * 3 / 4) });
5153
var position = 0;
5254
var bc = 0;
5355
var length, chr, bs;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
var $ = require('../internals/export');
3+
var arrayFrom = require('../internals/array-from');
34
var globalThis = require('../internals/global-this');
45
var getBuiltIn = require('../internals/get-built-in');
56
var uncurryThis = require('../internals/function-uncurry-this');
@@ -35,7 +36,8 @@ $({ global: true, bind: true, enumerable: true, forced: !BASIC || NO_ARG_RECEIVI
3536
// `webpack` dev server bug on IE global methods - use call(fn, global, ...)
3637
if (BASIC) return call($btoa, globalThis, toString(data));
3738
var string = toString(data);
38-
var output = [];
39+
// every 3 characters produce 4 bytes, so ceil(length * 4 / 3) is the number of bytes
40+
var output = arrayFrom({ length: Math.ceil(string.length * 4 / 3) });
3941
var position = 0;
4042
var map = i2c;
4143
var block, charCode;

0 commit comments

Comments
 (0)