Skip to content

Commit 2ad46c3

Browse files
Merge pull request #55 from UmamiAppearance/speed-improvements
Speed improvements
2 parents 2f03a21 + 5b802a8 commit 2ad46c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+548
-441
lines changed

cjs/base-ex.cjs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ class BaseConverter {
978978
}
979979

980980
this.decPadVal = decPadVal;
981+
this.powers = {};
981982
}
982983

983984
/**
@@ -1151,10 +1152,9 @@ class BaseConverter {
11511152
return new Uint8Array(0);
11521153
}
11531154

1154-
11551155
let bs = this.bsDec;
1156-
const byteArray = new Array();
1157-
1156+
const byteArray = [];
1157+
11581158
[...inputBaseStr].forEach(c => {
11591159
const index = charset.indexOf(c);
11601160
if (index > -1) {
@@ -1163,6 +1163,7 @@ class BaseConverter {
11631163
throw new DecodingError(c);
11641164
}
11651165
});
1166+
11661167

11671168
let padChars;
11681169

@@ -1187,17 +1188,23 @@ class BaseConverter {
11871188
// the blocksize.
11881189

11891190
for (let i=0, l=byteArray.length; i<l; i+=bs) {
1190-
1191+
11911192
// Build a subarray of bs bytes.
11921193
let n = 0n;
11931194

11941195
for (let j=0; j<bs; j++) {
1195-
n += BigInt(byteArray[i+j]) * this.pow(bs-1-j);
1196+
const exp = bs-1-j;
1197+
const pow = this.powers[exp] || (() => {
1198+
this.powers[exp] = BigInt(this.pow(exp));
1199+
return this.powers[exp];
1200+
})();
1201+
1202+
n += BigInt(byteArray[i+j]) * pow;
11961203
}
11971204

11981205
// To store the output chunks, initialize a
11991206
// new default array.
1200-
const subArray256 = new Array();
1207+
const subArray256 = [];
12011208

12021209
// The subarray gets converted into a bs*8-bit
12031210
// binary number "n", most significant byte
@@ -1225,7 +1232,7 @@ class BaseConverter {
12251232

12261233
// The subarray gets concatenated with the
12271234
// main array.
1228-
b256Array = b256Array.concat(subArray256);
1235+
b256Array.push(...subArray256);
12291236
}
12301237

12311238
// Remove padded zeros (or in case of LE all leading zeros)
@@ -1453,7 +1460,7 @@ class BaseTemplate {
14531460
/**
14541461
* [BaseEx|Base1 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-1.js}
14551462
*
1456-
* @version 0.7.8
1463+
* @version 0.7.9
14571464
* @author UmamiAppearance [mail@umamiappearance.eu]
14581465
* @license MIT
14591466
*/
@@ -1610,7 +1617,7 @@ class Base1 extends BaseTemplate {
16101617
/**
16111618
* [BaseEx|Base16 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-16.js}
16121619
*
1613-
* @version 0.7.8
1620+
* @version 0.7.9
16141621
* @author UmamiAppearance [mail@umamiappearance.eu]
16151622
* @license MIT
16161623
*/
@@ -1699,7 +1706,7 @@ class Base16 extends BaseTemplate {
16991706
/**
17001707
* [BaseEx|Base32 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-32.js}
17011708
*
1702-
* @version 0.7.8
1709+
* @version 0.7.9
17031710
* @author UmamiAppearance [mail@umamiappearance.eu]
17041711
* @license MIT
17051712
*/
@@ -1805,7 +1812,7 @@ class Base32 extends BaseTemplate {
18051812
/**
18061813
* [BaseEx|Base58 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-58.js}
18071814
*
1808-
* @version 0.7.8
1815+
* @version 0.7.9
18091816
* @author UmamiAppearance [mail@umamiappearance.eu]
18101817
* @license MIT
18111818
*/
@@ -1956,7 +1963,7 @@ class Base58 extends BaseTemplate{
19561963
/**
19571964
* [BaseEx|Base64 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-64.js}
19581965
*
1959-
* @version 0.7.8
1966+
* @version 0.7.9
19601967
* @author UmamiAppearance [mail@umamiappearance.eu]
19611968
* @license MIT
19621969
*/
@@ -2045,7 +2052,7 @@ class Base64 extends BaseTemplate {
20452052
/**
20462053
* [BaseEx|UUencode Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/uuencode.js}
20472054
*
2048-
* @version 0.7.8
2055+
* @version 0.7.9
20492056
* @author UmamiAppearance [mail@umamiappearance.eu]
20502057
* @license MIT
20512058
*/
@@ -2258,7 +2265,7 @@ const ees = () => {
22582265
/**
22592266
* [BaseEx|Base85 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-85.js}
22602267
*
2261-
* @version 0.7.8
2268+
* @version 0.7.9
22622269
* @author UmamiAppearance [mail@umamiappearance.eu]
22632270
* @license MIT
22642271
*/
@@ -2382,7 +2389,7 @@ class Base85 extends BaseTemplate {
23822389
/**
23832390
* [BaseEx|Base91 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-91.js}
23842391
*
2385-
* @version 0.7.8
2392+
* @version 0.7.9
23862393
* @author UmamiAppearance [mail@umamiappearance.eu]
23872394
* @license MIT AND BSD-3-Clause (Base91, Copyright (c) 2000-2006 Joachim Henke)
23882395
*/
@@ -2616,7 +2623,7 @@ class Base91 extends BaseTemplate {
26162623
/**
26172624
* [BaseEx|LEB128 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/leb-128.js}
26182625
*
2619-
* @version 0.7.8
2626+
* @version 0.7.9
26202627
* @author UmamiAppearance [mail@umamiappearance.eu]
26212628
* @license MIT
26222629
*/
@@ -2782,7 +2789,7 @@ class LEB128 extends BaseTemplate {
27822789
/**
27832790
* [BaseEx|Ecoji Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/ecoji.js}
27842791
*
2785-
* @version 0.7.8
2792+
* @version 0.7.9
27862793
* @author UmamiAppearance [mail@umamiappearance.eu]
27872794
* @license MIT OR Apache-2.0
27882795
* @see https://github.com/keith-turner/ecoji
@@ -3125,7 +3132,7 @@ class Ecoji extends BaseTemplate {
31253132
/**
31263133
* [BaseEx|Base2048 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-2048.js}
31273134
*
3128-
* @version 0.7.8
3135+
* @version 0.7.9
31293136
* @author UmamiAppearance [mail@umamiappearance.eu]
31303137
* @license MIT
31313138
*/
@@ -3304,7 +3311,7 @@ class Base2048 extends BaseTemplate {
33043311
/**
33053312
* [BaseEx|SimpleBase Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/simple-base.js}
33063313
*
3307-
* @version 0.7.8
3314+
* @version 0.7.9
33083315
* @author UmamiAppearance [mail@umamiappearance.eu]
33093316
* @license MIT
33103317
*/
@@ -3405,7 +3412,7 @@ let DP=20,RM=1,MAX_DP=1e6,NE=-7,PE=21,STRICT=!1,NAME="[big.js] ",INVALID=NAME+"I
34053412
/**
34063413
* [BaseEx|BasePhi Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-phi.js}
34073414
*
3408-
* @version 0.7.8
3415+
* @version 0.7.9
34093416
* @author UmamiAppearance [mail@umamiappearance.eu]
34103417
* @license MIT
34113418
*/
@@ -3743,7 +3750,7 @@ class BasePhi extends BaseTemplate {
37433750
/**
37443751
* [BaseEx|Byte Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/byte-converter.js}
37453752
*
3746-
* @version 0.7.8
3753+
* @version 0.7.9
37473754
* @author UmamiAppearance [mail@umamiappearance.eu]
37483755
* @license MIT
37493756
*/
@@ -3862,7 +3869,7 @@ class ByteConverter {
38623869
/**
38633870
* [BaseEx]{@link https://github.com/UmamiAppearance/BaseExJS}
38643871
*
3865-
* @version 0.7.8
3872+
* @version 0.7.9
38663873
* @author UmamiAppearance [mail@umamiappearance.eu]
38673874
* @license MIT
38683875
*/

cjs/base-ex.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/base-ex.esm.js

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ class BaseConverter {
976976
}
977977

978978
this.decPadVal = decPadVal;
979+
this.powers = {};
979980
}
980981

981982
/**
@@ -1149,10 +1150,9 @@ class BaseConverter {
11491150
return new Uint8Array(0);
11501151
}
11511152

1152-
11531153
let bs = this.bsDec;
1154-
const byteArray = new Array();
1155-
1154+
const byteArray = [];
1155+
11561156
[...inputBaseStr].forEach(c => {
11571157
const index = charset.indexOf(c);
11581158
if (index > -1) {
@@ -1161,6 +1161,7 @@ class BaseConverter {
11611161
throw new DecodingError(c);
11621162
}
11631163
});
1164+
11641165

11651166
let padChars;
11661167

@@ -1185,17 +1186,23 @@ class BaseConverter {
11851186
// the blocksize.
11861187

11871188
for (let i=0, l=byteArray.length; i<l; i+=bs) {
1188-
1189+
11891190
// Build a subarray of bs bytes.
11901191
let n = 0n;
11911192

11921193
for (let j=0; j<bs; j++) {
1193-
n += BigInt(byteArray[i+j]) * this.pow(bs-1-j);
1194+
const exp = bs-1-j;
1195+
const pow = this.powers[exp] || (() => {
1196+
this.powers[exp] = BigInt(this.pow(exp));
1197+
return this.powers[exp];
1198+
})();
1199+
1200+
n += BigInt(byteArray[i+j]) * pow;
11941201
}
11951202

11961203
// To store the output chunks, initialize a
11971204
// new default array.
1198-
const subArray256 = new Array();
1205+
const subArray256 = [];
11991206

12001207
// The subarray gets converted into a bs*8-bit
12011208
// binary number "n", most significant byte
@@ -1223,7 +1230,7 @@ class BaseConverter {
12231230

12241231
// The subarray gets concatenated with the
12251232
// main array.
1226-
b256Array = b256Array.concat(subArray256);
1233+
b256Array.push(...subArray256);
12271234
}
12281235

12291236
// Remove padded zeros (or in case of LE all leading zeros)
@@ -1451,7 +1458,7 @@ class BaseTemplate {
14511458
/**
14521459
* [BaseEx|Base1 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-1.js}
14531460
*
1454-
* @version 0.7.8
1461+
* @version 0.7.9
14551462
* @author UmamiAppearance [mail@umamiappearance.eu]
14561463
* @license MIT
14571464
*/
@@ -1608,7 +1615,7 @@ class Base1 extends BaseTemplate {
16081615
/**
16091616
* [BaseEx|Base16 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-16.js}
16101617
*
1611-
* @version 0.7.8
1618+
* @version 0.7.9
16121619
* @author UmamiAppearance [mail@umamiappearance.eu]
16131620
* @license MIT
16141621
*/
@@ -1697,7 +1704,7 @@ class Base16 extends BaseTemplate {
16971704
/**
16981705
* [BaseEx|Base32 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-32.js}
16991706
*
1700-
* @version 0.7.8
1707+
* @version 0.7.9
17011708
* @author UmamiAppearance [mail@umamiappearance.eu]
17021709
* @license MIT
17031710
*/
@@ -1803,7 +1810,7 @@ class Base32 extends BaseTemplate {
18031810
/**
18041811
* [BaseEx|Base58 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-58.js}
18051812
*
1806-
* @version 0.7.8
1813+
* @version 0.7.9
18071814
* @author UmamiAppearance [mail@umamiappearance.eu]
18081815
* @license MIT
18091816
*/
@@ -1954,7 +1961,7 @@ class Base58 extends BaseTemplate{
19541961
/**
19551962
* [BaseEx|Base64 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-64.js}
19561963
*
1957-
* @version 0.7.8
1964+
* @version 0.7.9
19581965
* @author UmamiAppearance [mail@umamiappearance.eu]
19591966
* @license MIT
19601967
*/
@@ -2043,7 +2050,7 @@ class Base64 extends BaseTemplate {
20432050
/**
20442051
* [BaseEx|UUencode Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/uuencode.js}
20452052
*
2046-
* @version 0.7.8
2053+
* @version 0.7.9
20472054
* @author UmamiAppearance [mail@umamiappearance.eu]
20482055
* @license MIT
20492056
*/
@@ -2256,7 +2263,7 @@ const ees = () => {
22562263
/**
22572264
* [BaseEx|Base85 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-85.js}
22582265
*
2259-
* @version 0.7.8
2266+
* @version 0.7.9
22602267
* @author UmamiAppearance [mail@umamiappearance.eu]
22612268
* @license MIT
22622269
*/
@@ -2380,7 +2387,7 @@ class Base85 extends BaseTemplate {
23802387
/**
23812388
* [BaseEx|Base91 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-91.js}
23822389
*
2383-
* @version 0.7.8
2390+
* @version 0.7.9
23842391
* @author UmamiAppearance [mail@umamiappearance.eu]
23852392
* @license MIT AND BSD-3-Clause (Base91, Copyright (c) 2000-2006 Joachim Henke)
23862393
*/
@@ -2614,7 +2621,7 @@ class Base91 extends BaseTemplate {
26142621
/**
26152622
* [BaseEx|LEB128 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/leb-128.js}
26162623
*
2617-
* @version 0.7.8
2624+
* @version 0.7.9
26182625
* @author UmamiAppearance [mail@umamiappearance.eu]
26192626
* @license MIT
26202627
*/
@@ -2780,7 +2787,7 @@ class LEB128 extends BaseTemplate {
27802787
/**
27812788
* [BaseEx|Ecoji Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/ecoji.js}
27822789
*
2783-
* @version 0.7.8
2790+
* @version 0.7.9
27842791
* @author UmamiAppearance [mail@umamiappearance.eu]
27852792
* @license MIT OR Apache-2.0
27862793
* @see https://github.com/keith-turner/ecoji
@@ -3123,7 +3130,7 @@ class Ecoji extends BaseTemplate {
31233130
/**
31243131
* [BaseEx|Base2048 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-2048.js}
31253132
*
3126-
* @version 0.7.8
3133+
* @version 0.7.9
31273134
* @author UmamiAppearance [mail@umamiappearance.eu]
31283135
* @license MIT
31293136
*/
@@ -3302,7 +3309,7 @@ class Base2048 extends BaseTemplate {
33023309
/**
33033310
* [BaseEx|SimpleBase Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/simple-base.js}
33043311
*
3305-
* @version 0.7.8
3312+
* @version 0.7.9
33063313
* @author UmamiAppearance [mail@umamiappearance.eu]
33073314
* @license MIT
33083315
*/
@@ -3403,7 +3410,7 @@ let DP=20,RM=1,MAX_DP=1e6,NE=-7,PE=21,STRICT=!1,NAME="[big.js] ",INVALID=NAME+"I
34033410
/**
34043411
* [BaseEx|BasePhi Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-phi.js}
34053412
*
3406-
* @version 0.7.8
3413+
* @version 0.7.9
34073414
* @author UmamiAppearance [mail@umamiappearance.eu]
34083415
* @license MIT
34093416
*/
@@ -3741,7 +3748,7 @@ class BasePhi extends BaseTemplate {
37413748
/**
37423749
* [BaseEx|Byte Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/byte-converter.js}
37433750
*
3744-
* @version 0.7.8
3751+
* @version 0.7.9
37453752
* @author UmamiAppearance [mail@umamiappearance.eu]
37463753
* @license MIT
37473754
*/
@@ -3860,7 +3867,7 @@ class ByteConverter {
38603867
/**
38613868
* [BaseEx]{@link https://github.com/UmamiAppearance/BaseExJS}
38623869
*
3863-
* @version 0.7.8
3870+
* @version 0.7.9
38643871
* @author UmamiAppearance [mail@umamiappearance.eu]
38653872
* @license MIT
38663873
*/

0 commit comments

Comments
 (0)