coins: optimize.

This commit is contained in:
Christopher Jeffrey 2016-08-18 00:16:28 -07:00
parent 578ff8f684
commit b0aebb9c84
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 8 additions and 4 deletions

View File

@ -1071,11 +1071,11 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
for (i = 0; i < view.length; i++) {
coins = view[i];
if (coins.size() === 0) {
raw = coins.toRaw();
if (!raw) {
this.del(layout.c(coins.hash));
this.coinCache.remove(coins.hash);
} else {
raw = coins.toRaw();
this.put(layout.c(coins.hash), raw);
this.coinCache.set(coins.hash, raw);
}
@ -1172,11 +1172,11 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, callback) {
for (i = 0; i < view.length; i++) {
coins = view[i];
if (coins.size() === 0) {
raw = coins.toRaw();
if (!raw) {
self.del(layout.c(coins.hash));
self.coinCache.remove(coins.hash);
} else {
raw = coins.toRaw();
self.put(layout.c(coins.hash), raw);
self.coinCache.set(coins.hash, raw);
}

View File

@ -224,6 +224,10 @@ Coins.prototype.toRaw = function toRaw(writer) {
var length = this.size();
var i, output, bits, fstart, flen, bit, oct;
// Return nothing if we're fully spent.
if (length === 0)
return writer;
// Varint version: hopefully some smartass
// miner doesn't start mining `-1` versions.
p.writeVarint(this.version);