From 8e6819714bcbce09d0b2d1971371b88ffd5c699c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 26 Jan 2017 11:23:55 -0800 Subject: [PATCH] merkleblock: improve extractTree perf. --- lib/primitives/merkleblock.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index 724f5ca6..47b93543 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -196,7 +196,7 @@ MerkleBlock.prototype.extractTree = function extractTree() { var indexes = []; var map = {}; var failed = false; - var hashes = []; + var hashes = this.hashes; var flags = this.flags; var totalTX = this.totalTX; var height = 0; @@ -253,15 +253,12 @@ MerkleBlock.prototype.extractTree = function extractTree() { if (totalTX > consensus.MAX_BLOCK_SIZE / 60) throw new Error('Too many transactions.'); - if (this.hashes.length > totalTX) + if (hashes.length > totalTX) throw new Error('Too many hashes.'); - if (flags.length * 8 < this.hashes.length) + if (flags.length * 8 < hashes.length) throw new Error('Flags too small.'); - for (p = 0; p < this.hashes.length; p++) - hashes.push(this.hashes[p]); - while (width(height) > 1) height++;