From b1b9ef34a9585af65fd1fd6c7599d3b628627146 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 26 May 2021 16:02:49 +0200 Subject: [PATCH] cache buffer in local var --- lib/util/createHash.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/util/createHash.js b/lib/util/createHash.js index bbabc61306c..81cfa0a221c 100644 --- a/lib/util/createHash.js +++ b/lib/util/createHash.js @@ -67,6 +67,7 @@ class BulkUpdateDecorator extends Hash { */ digest(encoding) { let digestCache; + const buffer = this.buffer; if (this.hash === undefined) { // short data for hash, we can use caching const cacheKey = `${this.hashKey}-${encoding}`; @@ -74,18 +75,18 @@ class BulkUpdateDecorator extends Hash { if (digestCache === undefined) { digestCache = digestCaches[cacheKey] = new Map(); } - const cacheEntry = digestCache.get(this.buffer); + const cacheEntry = digestCache.get(buffer); if (cacheEntry !== undefined) return cacheEntry; this.hash = this.hashFactory(); } - if (this.buffer.length > 0) { - this.hash.update(this.buffer); + if (buffer.length > 0) { + this.hash.update(buffer); } const digestResult = this.hash.digest(encoding); const result = typeof digestResult === "string" ? digestResult : digestResult.toString(); if (digestCache !== undefined) { - digestCache.set(this.buffer, result); + digestCache.set(buffer, result); } return result; }