From 227e9a18b25b63286be3721f350a075f430dd456 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 27 Jul 2016 02:25:30 -0700 Subject: [PATCH] workers: optimize parser. --- lib/bcoin/workers.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bcoin/workers.js b/lib/bcoin/workers.js index 52be54c5..9b9fb940 100644 --- a/lib/bcoin/workers.js +++ b/lib/bcoin/workers.js @@ -961,7 +961,7 @@ Parser.prototype.feed = function feed(data) { if (this.pendingTotal < this.waiting) break; - chunk = Buffer.concat(this.pending); + chunk = concat(this.pending); if (chunk.length > this.waiting) { data = chunk.slice(this.waiting); @@ -1107,6 +1107,12 @@ function fromError(err) { return [err.message, err.stack + '', err.type]; } +function concat(buffers) { + return buffers.length > 1 + ? Buffer.concat(buffers) + : buffers[0]; +} + /* * Expose */