Skip to content

Commit f729053

Browse files
authored
Merge pull request #167 from ctomacheski/main
Improve performance by stop using the mapFn param on Uint8Array.from …
2 parents 3226fbe + a9a994f commit f729053

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

base64.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ const b64re =
3232
const _fromCC = String.fromCharCode.bind(String);
3333
const _U8Afrom = typeof Uint8Array.from === 'function'
3434
? Uint8Array.from.bind(Uint8Array)
35-
: (it, fn: (any) => number = (x) => x) =>
36-
new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
35+
: (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
3736
const _mkUriSafe = (src: string) => src
3837
.replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_');
3938
const _tidyB64 = (s: string) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
@@ -195,7 +194,7 @@ const _atob = _hasatob ? (asc: string) => atob(_tidyB64(asc))
195194
//
196195
const _toUint8Array = _hasBuffer
197196
? (a: string) => _U8Afrom(Buffer.from(a, 'base64'))
198-
: (a: string) => _U8Afrom(_atob(a), c => c.charCodeAt(0));
197+
: (a: string) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
199198
/**
200199
* converts a Base64 string to a Uint8Array.
201200
*/

0 commit comments

Comments
 (0)