Skip to content

Commit

Permalink
perf: cache this.exclude.shouldInstrument
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 6, 2022
1 parent ae1f5e5 commit 271384c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Report {
excludeNodeModules: excludeNodeModules
})
this.excludeAfterRemap = excludeAfterRemap
this.excludeShouldInstrumentCache = new Map()
this.omitRelative = omitRelative
this.sourceMapCache = {}
this.wrapperLength = wrapperLength
Expand Down Expand Up @@ -96,7 +97,7 @@ class Report {
const path = resolve(this.resolve, v8ScriptCov.url)
const converter = v8toIstanbul(path, this.wrapperLength, sources, (path) => {
if (this.excludeAfterRemap) {
return !this.exclude.shouldInstrument(path)
return !this._shouldInstrument(path)
}
})
await converter.load()
Expand Down Expand Up @@ -287,7 +288,7 @@ class Report {
}
}
if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
if (this.excludeAfterRemap || this.exclude.shouldInstrument(v8ScriptCov.url)) {
if (this.excludeAfterRemap || this._shouldInstrument(v8ScriptCov.url)) {
result.push(v8ScriptCov)
}
}
Expand All @@ -311,6 +312,23 @@ class Report {
}
return cache
}

/**
* this.exclude.shouldInstrument with cache
*
* @private
* @return {boolean}
*/
_shouldInstrument (filename) {
const cacheResult = this.excludeShouldInstrumentCache.get(filename)
if (cacheResult !== undefined) {
return cacheResult
}

const result = this.exclude.shouldInstrument(filename)
this.excludeShouldInstrumentCache.set(filename, result)
return result
}
}

module.exports = function (opts) {
Expand Down

0 comments on commit 271384c

Please sign in to comment.