Script: early exit in chunk.reduce

This commit is contained in:
Daniel Cousens 2014-06-13 09:36:11 +10:00
parent be29f50457
commit de1571647a

View file

@ -43,17 +43,11 @@ Script.fromChunks = function(chunks) {
assert(Array.isArray(chunks), 'Expected Array, got ' + chunks)
var bufferSize = chunks.reduce(function(accum, chunk) {
var chunkSize
if (Buffer.isBuffer(chunk)) {
chunkSize = bufferutils.pushDataSize(chunk.length) + chunk.length
} else {
chunkSize = 1
return accum + bufferutils.pushDataSize(chunk.length) + chunk.length
}
return accum + chunkSize
return accum + 1
}, 0.0)
var buffer = new Buffer(bufferSize)
@ -67,8 +61,6 @@ Script.fromChunks = function(chunks) {
offset += chunk.length
} else {
assert(typeof chunk == 'number')
buffer.writeUInt8(chunk, offset)
offset += 1
}