Skip to content

Commit 6b40b16

Browse files
committed
inline flush, reduce bulk size
1 parent a0ef93f commit 6b40b16

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/util/createHash.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const BULK_SIZE = 10000;
7+
const BULK_SIZE = 1000;
88

99
class BulkUpdateDecorator {
1010
constructor(hash) {
@@ -14,26 +14,25 @@ class BulkUpdateDecorator {
1414

1515
update(data, inputEncoding) {
1616
if(inputEncoding !== undefined || typeof data !== "string" || data.length > BULK_SIZE) {
17-
if(this.buffer.length > 0)
18-
this._flush();
17+
if(this.buffer.length > 0) {
18+
this.hash.update(this.buffer);
19+
this.buffer = "";
20+
}
1921
this.hash.update(data, inputEncoding);
2022
} else {
2123
this.buffer += data;
2224
if(this.buffer.length > BULK_SIZE) {
23-
this._flush();
25+
this.hash.update(this.buffer);
26+
this.buffer = "";
2427
}
2528
}
2629
return this;
2730
}
2831

29-
_flush() {
30-
this.hash.update(this.buffer);
31-
this.buffer = "";
32-
}
33-
3432
digest(encoding) {
35-
if(this.buffer.length > 0)
36-
this._flush();
33+
if(this.buffer.length > 0) {
34+
this.hash.update(this.buffer);
35+
}
3736
return this.hash.digest(encoding);
3837
}
3938
}

0 commit comments

Comments
 (0)