-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from UmamiAppearance/speed-improvements
Speed improvements
- Loading branch information
Showing
80 changed files
with
548 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -978,6 +978,7 @@ class BaseConverter { | |
} | ||
|
||
this.decPadVal = decPadVal; | ||
this.powers = {}; | ||
} | ||
|
||
/** | ||
|
@@ -1151,10 +1152,9 @@ class BaseConverter { | |
return new Uint8Array(0); | ||
} | ||
|
||
|
||
let bs = this.bsDec; | ||
const byteArray = new Array(); | ||
|
||
const byteArray = []; | ||
[...inputBaseStr].forEach(c => { | ||
const index = charset.indexOf(c); | ||
if (index > -1) { | ||
|
@@ -1163,6 +1163,7 @@ class BaseConverter { | |
throw new DecodingError(c); | ||
} | ||
}); | ||
|
||
|
||
let padChars; | ||
|
||
|
@@ -1187,17 +1188,23 @@ class BaseConverter { | |
// the blocksize. | ||
|
||
for (let i=0, l=byteArray.length; i<l; i+=bs) { | ||
|
||
// Build a subarray of bs bytes. | ||
let n = 0n; | ||
|
||
for (let j=0; j<bs; j++) { | ||
n += BigInt(byteArray[i+j]) * this.pow(bs-1-j); | ||
const exp = bs-1-j; | ||
const pow = this.powers[exp] || (() => { | ||
this.powers[exp] = BigInt(this.pow(exp)); | ||
return this.powers[exp]; | ||
})(); | ||
|
||
n += BigInt(byteArray[i+j]) * pow; | ||
} | ||
|
||
// To store the output chunks, initialize a | ||
// new default array. | ||
const subArray256 = new Array(); | ||
const subArray256 = []; | ||
|
||
// The subarray gets converted into a bs*8-bit | ||
// binary number "n", most significant byte | ||
|
@@ -1225,7 +1232,7 @@ class BaseConverter { | |
|
||
// The subarray gets concatenated with the | ||
// main array. | ||
b256Array = b256Array.concat(subArray256); | ||
b256Array.push(...subArray256); | ||
} | ||
|
||
// Remove padded zeros (or in case of LE all leading zeros) | ||
|
@@ -1453,7 +1460,7 @@ class BaseTemplate { | |
/** | ||
* [BaseEx|Base1 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-1.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1610,7 +1617,7 @@ class Base1 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base16 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-16.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1699,7 +1706,7 @@ class Base16 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base32 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-32.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1805,7 +1812,7 @@ class Base32 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base58 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-58.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1956,7 +1963,7 @@ class Base58 extends BaseTemplate{ | |
/** | ||
* [BaseEx|Base64 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-64.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2045,7 +2052,7 @@ class Base64 extends BaseTemplate { | |
/** | ||
* [BaseEx|UUencode Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/uuencode.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2258,7 +2265,7 @@ const ees = () => { | |
/** | ||
* [BaseEx|Base85 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-85.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2382,7 +2389,7 @@ class Base85 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base91 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-91.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT AND BSD-3-Clause (Base91, Copyright (c) 2000-2006 Joachim Henke) | ||
*/ | ||
|
@@ -2616,7 +2623,7 @@ class Base91 extends BaseTemplate { | |
/** | ||
* [BaseEx|LEB128 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/leb-128.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2782,7 +2789,7 @@ class LEB128 extends BaseTemplate { | |
/** | ||
* [BaseEx|Ecoji Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/ecoji.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT OR Apache-2.0 | ||
* @see https://github.com/keith-turner/ecoji | ||
|
@@ -3125,7 +3132,7 @@ class Ecoji extends BaseTemplate { | |
/** | ||
* [BaseEx|Base2048 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-2048.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3304,7 +3311,7 @@ class Base2048 extends BaseTemplate { | |
/** | ||
* [BaseEx|SimpleBase Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/simple-base.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3405,7 +3412,7 @@ let DP=20,RM=1,MAX_DP=1e6,NE=-7,PE=21,STRICT=!1,NAME="[big.js] ",INVALID=NAME+"I | |
/** | ||
* [BaseEx|BasePhi Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-phi.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3743,7 +3750,7 @@ class BasePhi extends BaseTemplate { | |
/** | ||
* [BaseEx|Byte Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/byte-converter.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3862,7 +3869,7 @@ class ByteConverter { | |
/** | ||
* [BaseEx]{@link https://github.com/UmamiAppearance/BaseExJS} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -976,6 +976,7 @@ class BaseConverter { | |
} | ||
|
||
this.decPadVal = decPadVal; | ||
this.powers = {}; | ||
} | ||
|
||
/** | ||
|
@@ -1149,10 +1150,9 @@ class BaseConverter { | |
return new Uint8Array(0); | ||
} | ||
|
||
|
||
let bs = this.bsDec; | ||
const byteArray = new Array(); | ||
|
||
const byteArray = []; | ||
[...inputBaseStr].forEach(c => { | ||
const index = charset.indexOf(c); | ||
if (index > -1) { | ||
|
@@ -1161,6 +1161,7 @@ class BaseConverter { | |
throw new DecodingError(c); | ||
} | ||
}); | ||
|
||
|
||
let padChars; | ||
|
||
|
@@ -1185,17 +1186,23 @@ class BaseConverter { | |
// the blocksize. | ||
|
||
for (let i=0, l=byteArray.length; i<l; i+=bs) { | ||
|
||
// Build a subarray of bs bytes. | ||
let n = 0n; | ||
|
||
for (let j=0; j<bs; j++) { | ||
n += BigInt(byteArray[i+j]) * this.pow(bs-1-j); | ||
const exp = bs-1-j; | ||
const pow = this.powers[exp] || (() => { | ||
this.powers[exp] = BigInt(this.pow(exp)); | ||
return this.powers[exp]; | ||
})(); | ||
|
||
n += BigInt(byteArray[i+j]) * pow; | ||
} | ||
|
||
// To store the output chunks, initialize a | ||
// new default array. | ||
const subArray256 = new Array(); | ||
const subArray256 = []; | ||
|
||
// The subarray gets converted into a bs*8-bit | ||
// binary number "n", most significant byte | ||
|
@@ -1223,7 +1230,7 @@ class BaseConverter { | |
|
||
// The subarray gets concatenated with the | ||
// main array. | ||
b256Array = b256Array.concat(subArray256); | ||
b256Array.push(...subArray256); | ||
} | ||
|
||
// Remove padded zeros (or in case of LE all leading zeros) | ||
|
@@ -1451,7 +1458,7 @@ class BaseTemplate { | |
/** | ||
* [BaseEx|Base1 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-1.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1608,7 +1615,7 @@ class Base1 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base16 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-16.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1697,7 +1704,7 @@ class Base16 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base32 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-32.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1803,7 +1810,7 @@ class Base32 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base58 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-58.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -1954,7 +1961,7 @@ class Base58 extends BaseTemplate{ | |
/** | ||
* [BaseEx|Base64 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-64.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2043,7 +2050,7 @@ class Base64 extends BaseTemplate { | |
/** | ||
* [BaseEx|UUencode Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/uuencode.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2256,7 +2263,7 @@ const ees = () => { | |
/** | ||
* [BaseEx|Base85 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-85.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2380,7 +2387,7 @@ class Base85 extends BaseTemplate { | |
/** | ||
* [BaseEx|Base91 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-91.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT AND BSD-3-Clause (Base91, Copyright (c) 2000-2006 Joachim Henke) | ||
*/ | ||
|
@@ -2614,7 +2621,7 @@ class Base91 extends BaseTemplate { | |
/** | ||
* [BaseEx|LEB128 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/leb-128.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -2780,7 +2787,7 @@ class LEB128 extends BaseTemplate { | |
/** | ||
* [BaseEx|Ecoji Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/ecoji.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT OR Apache-2.0 | ||
* @see https://github.com/keith-turner/ecoji | ||
|
@@ -3123,7 +3130,7 @@ class Ecoji extends BaseTemplate { | |
/** | ||
* [BaseEx|Base2048 Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-2048.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3302,7 +3309,7 @@ class Base2048 extends BaseTemplate { | |
/** | ||
* [BaseEx|SimpleBase Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/simple-base.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3403,7 +3410,7 @@ let DP=20,RM=1,MAX_DP=1e6,NE=-7,PE=21,STRICT=!1,NAME="[big.js] ",INVALID=NAME+"I | |
/** | ||
* [BaseEx|BasePhi Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/base-phi.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3741,7 +3748,7 @@ class BasePhi extends BaseTemplate { | |
/** | ||
* [BaseEx|Byte Converter]{@link https://github.com/UmamiAppearance/BaseExJS/blob/main/src/converters/byte-converter.js} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
@@ -3860,7 +3867,7 @@ class ByteConverter { | |
/** | ||
* [BaseEx]{@link https://github.com/UmamiAppearance/BaseExJS} | ||
* | ||
* @version 0.7.8 | ||
* @version 0.7.9 | ||
* @author UmamiAppearance [[email protected]] | ||
* @license MIT | ||
*/ | ||
|
Oops, something went wrong.