Apply suggestions from code review

avoid regex in partial txid ordering conversion

Co-authored-by: Jonathan Underwood <jonathan.underwood4649@gmail.com>
This commit is contained in:
mononaut 2023-07-03 11:55:43 -04:00 committed by GitHub
parent 23d487b904
commit d16d961cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -56,5 +56,11 @@ function mempoolFromArrayBuffer(buf: ArrayBuffer): ThreadTransaction[] {
}
function txidToOrdering(txid: string): number {
return parseInt(txid.slice(56).match(/../g)?.reverse().join('') as string, 16);
return (
((parseInt(txid.substring(62, 64), 16) << 24) |
(parseInt(txid.substring(60, 62), 16) << 16) |
(parseInt(txid.substring(58, 60), 16) << 8) |
parseInt(txid.substring(56, 58), 16)) >>>
0
);
}

View File

@ -158,7 +158,13 @@ class TransactionUtils {
// returns the most significant 4 bytes of the txid as an integer
public txidToOrdering(txid: string): number {
return parseInt(txid.slice(56).match(/../g)?.reverse().join('') as string, 16);
return (
((parseInt(txid.substring(62, 64), 16) << 24) |
(parseInt(txid.substring(60, 62), 16) << 16) |
(parseInt(txid.substring(58, 60), 16) << 8) |
parseInt(txid.substring(56, 58), 16)) >>>
0
);
}
}