Script: early exit in chunk.reduce
This commit is contained in:
parent
be29f50457
commit
de1571647a
1 changed files with 2 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue