From e3e324441b0adc3e1e4e7814e5eb6848683d3e6d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 23 May 2014 23:13:16 -0500 Subject: [PATCH] block: improve performance of duplicate tx check. --- lib/bcoin/block.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index ecafb236..c21d16cb 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -232,14 +232,11 @@ Block.prototype._checkBlock = function checkBlock() { this.merkleTree = this._buildMerkle(); // Check for duplicate tx ids - var unique = []; + var unique = {}; for (var i = 0; i < this.txs.length; i++) { - if (!~unique.indexOf(this.txs[i].hash('hex'))) { - unique.push(this.txs[i].hash('hex')); - } - } - if (unique.length !== this.txs.length) { - return false; + var hash = this.txs[i].hash('hex'); + if (unique[hash]) return false; + unique[hash] = true; } // Check to make sure block does not have more opcodes than MAX_BLOCK_SIGOPS