Skip to content

Commit

Permalink
Memoize NormalModule.size()
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgepigdaniel committed Sep 20, 2019
1 parent b07d3b6 commit 2aef0b6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/NormalModule.js
Expand Up @@ -87,6 +87,7 @@ class NormalModule extends Module {
// Info from Build
this.error = null;
this._source = null;
this._sourceSize = null;
this._buildHash = "";
this.buildTimestamp = undefined;
/** @private @type {Map<string, CachedSourceEntry>} */
Expand Down Expand Up @@ -347,6 +348,7 @@ class NormalModule extends Module {
resourceBuffer,
sourceMap
);
this._sourceSize = null;
this._ast =
typeof extraInfo === "object" &&
extraInfo !== null &&
Expand All @@ -366,6 +368,7 @@ class NormalModule extends Module {
this._source = new RawSource(
"throw new Error(" + JSON.stringify(this.error.message) + ");"
);
this._sourceSize = null;
this._ast = null;
}

Expand Down Expand Up @@ -425,6 +428,7 @@ class NormalModule extends Module {
this.buildTimestamp = Date.now();
this.built = true;
this._source = null;
this._sourceSize = null;
this._ast = null;
this._buildHash = "";
this.error = null;
Expand Down Expand Up @@ -559,7 +563,10 @@ class NormalModule extends Module {
}

size() {
return this._source ? this._source.size() : -1;
if (this._sourceSize === null) {
this._sourceSize = this._source ? this._source.size() : -1;
}
return this._sourceSize;
}

/**
Expand Down

0 comments on commit 2aef0b6

Please sign in to comment.