From b98ca596d15285a2d0688f6e01a0615b83099cd6 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 23 Oct 2016 13:35:16 -0700 Subject: [PATCH] lru: minor. --- lib/utils/lru.js | 18 +++++++++++------- lib/wallet/walletdb.js | 8 ++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/utils/lru.js b/lib/utils/lru.js index 839d6aec..fda80bb7 100644 --- a/lib/utils/lru.js +++ b/lib/utils/lru.js @@ -337,7 +337,7 @@ LRU.prototype.batch = function batch() { }; /** - * Start the pending LRU batch. + * Start the pending batch. */ LRU.prototype.start = function start() { @@ -346,16 +346,16 @@ LRU.prototype.start = function start() { }; /** - * Clear the pending LRU batch. + * Clear the pending batch. */ LRU.prototype.clear = function clear() { assert(this.pending); - this.pending = this.batch(); + this.pending.clear(); }; /** - * Drop the pending LRU batch. + * Drop the pending batch. */ LRU.prototype.drop = function drop() { @@ -364,7 +364,7 @@ LRU.prototype.drop = function drop() { }; /** - * Commit the pending LRU batch. + * Commit the pending batch. */ LRU.prototype.commit = function commit() { @@ -374,7 +374,7 @@ LRU.prototype.commit = function commit() { }; /** - * Push an item onto the pending LRU batch. + * Push an item onto the pending batch. * @param {String} key * @param {Object} value */ @@ -385,7 +385,7 @@ LRU.prototype.push = function push(key, value) { }; /** - * Push a removal onto the pending LRU batch. + * Push a removal onto the pending batch. * @param {String} key */ @@ -427,6 +427,10 @@ LRUBatch.prototype.remove = function remove(key) { this.ops.push(new LRUOp(true, key)); }; +LRUBatch.prototype.clear = function clear() { + this.ops.length = 0; +}; + LRUBatch.prototype.commit = function commit() { var i, op; diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index ed118676..a2aaec09 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -1583,7 +1583,7 @@ WalletDB.prototype.addBlock = co(function* addBlock(entry, txs) { if (entry.height <= this.height) { this.logger.warning('Node is connecting low blocks in wallet.'); - return; + return 0; } if (entry.height !== this.height + 1) @@ -1610,7 +1610,7 @@ WalletDB.prototype._addBlock = co(function* addBlock(entry, txs) { if (entry.height <= this.network.checkpoints.lastHeight) { block = WalletBlock.fromEntry(entry); yield this.setBlock(block); - return; + return 0; } } @@ -1650,7 +1650,7 @@ WalletDB.prototype.removeBlock = co(function* removeBlock(entry) { if (entry.height > this.height) { this.logger.warning('Node is disconnecting high blocks in wallet.'); - return; + return 0; } if (entry.height !== this.height) @@ -1674,7 +1674,7 @@ WalletDB.prototype._removeBlock = co(function* removeBlock(entry) { var i, tx, prev; if (!block) - return; + return 0; prev = yield this.getBlock(entry.height - 1); assert(prev);