Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
perf: Cache isDirectoryIgnored calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Oct 3, 2022
1 parent 3d1eaf6 commit c5e6720
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ export class ConfigArray extends Array {

// init cache
dataCache.set(this, {
explicitMatches: new Map()
explicitMatches: new Map(),
directoryMatches: new Map(),
files: undefined,
ignores: undefined
});

// load the configs into this array
Expand Down Expand Up @@ -742,7 +745,15 @@ export class ConfigArray extends Array {
throw new Error(`Directory ${directoryPath} is outside of the basePath ${this.basePath}`);
}

return this.ignores.some(matcher => {
// first check the cache
const cache = dataCache.get(this).directoryMatches;

if (cache.has(relativeDirectoryPath)) {
return cache.get(relativeDirectoryPath);
}

// if we've made it here, it means there's nothing in the cache
const result = this.ignores.some(matcher => {

if (typeof matcher === "function") {
return matcher(relativeDirectoryPath);
Expand All @@ -760,6 +771,10 @@ export class ConfigArray extends Array {

return doMatch(relativeDirectoryPath, matcher);
});

cache.set(relativeDirectoryPath, result);

return result;
}

}

0 comments on commit c5e6720

Please sign in to comment.