Additional speed optimizations (#1605)
This commit is contained in:
@@ -7,6 +7,7 @@ Changes:
|
||||
- Add `arrayUnzip` as reverse of `arrayZip`
|
||||
- Adjust `isAscii` check to disallow `\t`, `\n`, & `\r` characters
|
||||
- Adjust `nobody` zero-key pair with pre-computed address
|
||||
- Various internal speed optimizations
|
||||
|
||||
|
||||
## 10.0.2 Jul 10, 2022
|
||||
|
||||
@@ -78,12 +78,12 @@ describe('u8aToHex', (): void => {
|
||||
).toEqual('0x68656c6c6f20776f726c64');
|
||||
});
|
||||
|
||||
perfCmp('u8aToHex (32k)', ['u8aToHexBuffer', 'u8aToHex'], 2000, [[ptest32k]], (s: Uint8Array, isSecond) =>
|
||||
perfCmp('u8aToHex (32k)', ['u8aToHexBuffer', 'u8aToHex'], 1000, [[ptest32k]], (s: Uint8Array, isSecond) =>
|
||||
isSecond
|
||||
? u8aToHex(s)
|
||||
: u8aToHexBuffer(s)
|
||||
);
|
||||
perfCmp('u8aToHex (128)', ['u8aToHexBuffer', 'u8aToHex'], 100000, [[ptest256]], (s: Uint8Array, isSecond) =>
|
||||
perfCmp('u8aToHex (128)', ['u8aToHexBuffer', 'u8aToHex'], 200_000, [[ptest256]], (s: Uint8Array, isSecond) =>
|
||||
isSecond
|
||||
? u8aToHex(s)
|
||||
: u8aToHexBuffer(s)
|
||||
|
||||
@@ -20,19 +20,16 @@ for (let i = 0; i < 256; i++) {
|
||||
|
||||
/** @internal */
|
||||
function hex (value: Uint8Array): string {
|
||||
const mod = value.length % 2;
|
||||
const length = value.length - mod;
|
||||
const dv = new DataView(value.buffer, value.byteOffset);
|
||||
const mod = (value.length % 2) | 0;
|
||||
const length = (value.length - mod) | 0;
|
||||
let result = '';
|
||||
|
||||
for (let i = 0; i < length; i += 2) {
|
||||
// we only use getUint16 here instead of getUint32 - at least in our
|
||||
// tests this is faster to execute (both long & short strings tested)
|
||||
result += U16[dv.getUint16(i)];
|
||||
result += U16[(value[i] << 8) | value[i + 1]];
|
||||
}
|
||||
|
||||
if (mod) {
|
||||
result += U8[dv.getUint8(length)];
|
||||
result += U8[value[length] | 0];
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user