From 6b40b1699efca7afee6724ef566ac9431bdd17ad Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 23 Nov 2017 11:44:56 +0100 Subject: [PATCH] inline flush, reduce bulk size --- lib/util/createHash.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/util/createHash.js b/lib/util/createHash.js index 16f919908..85921456b 100644 --- a/lib/util/createHash.js +++ b/lib/util/createHash.js @@ -4,7 +4,7 @@ */ "use strict"; -const BULK_SIZE = 10000; +const BULK_SIZE = 1000; class BulkUpdateDecorator { constructor(hash) { @@ -14,26 +14,25 @@ class BulkUpdateDecorator { update(data, inputEncoding) { if(inputEncoding !== undefined || typeof data !== "string" || data.length > BULK_SIZE) { - if(this.buffer.length > 0) - this._flush(); + if(this.buffer.length > 0) { + this.hash.update(this.buffer); + this.buffer = ""; + } this.hash.update(data, inputEncoding); } else { this.buffer += data; if(this.buffer.length > BULK_SIZE) { - this._flush(); + this.hash.update(this.buffer); + this.buffer = ""; } } return this; } - _flush() { - this.hash.update(this.buffer); - this.buffer = ""; - } - digest(encoding) { - if(this.buffer.length > 0) - this._flush(); + if(this.buffer.length > 0) { + this.hash.update(this.buffer); + } return this.hash.digest(encoding); } }