inline flush, reduce bulk size

This commit is contained in:
Tobias Koppers 2017-11-23 11:44:56 +01:00
parent a0ef93f939
commit 6b40b1699e
1 changed files with 10 additions and 11 deletions

View File

@ -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);
}
}