From 22d357c53c1816e8bb0995a0fd13a5b44730be8b Mon Sep 17 00:00:00 2001 From: junderw Date: Wed, 5 Jul 2023 08:39:01 -0700 Subject: [PATCH] Faster txid to u32 parsing --- backend/src/__tests__/gbt/gbt-tests.ts | 12 ++++++------ backend/src/api/transaction-utils.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/src/__tests__/gbt/gbt-tests.ts b/backend/src/__tests__/gbt/gbt-tests.ts index 8af76a47c..0651faac4 100644 --- a/backend/src/__tests__/gbt/gbt-tests.ts +++ b/backend/src/__tests__/gbt/gbt-tests.ts @@ -58,11 +58,11 @@ function mempoolFromArrayBuffer(buf: ArrayBuffer): { mempool: ThreadTransaction[ } function txidToOrdering(txid: string): number { - 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 + return parseInt( + txid.substr(62, 2) + + txid.substr(60, 2) + + txid.substr(58, 2) + + txid.substr(56, 2), + 16 ); } diff --git a/backend/src/api/transaction-utils.ts b/backend/src/api/transaction-utils.ts index 92f5b71c5..8bebc42d8 100644 --- a/backend/src/api/transaction-utils.ts +++ b/backend/src/api/transaction-utils.ts @@ -158,12 +158,12 @@ class TransactionUtils { // returns the most significant 4 bytes of the txid as an integer public txidToOrdering(txid: string): number { - 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 + return parseInt( + txid.substr(62, 2) + + txid.substr(60, 2) + + txid.substr(58, 2) + + txid.substr(56, 2), + 16 ); } }