Skip to content

Commit 95ccf7e

Browse files
committed
perf(fmt): optimize root gitignore matching
1 parent 68c6f25 commit 95ccf7e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/rstack/src/fmt/discoverPaths.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ class GitIgnoreMatcher {
164164
}
165165

166166
#matches(relativePath: string, isDirectory: boolean): boolean {
167+
// Most repositories only use a root `.gitignore`. Avoid checking every path
168+
// segment when no nested matcher can override its result.
169+
const rootMatcher = this.#matchers.size === 1 ? this.#matchers.get(this.#rootPath) : undefined;
170+
if (rootMatcher) {
171+
// `ignore` expects POSIX separators and uses a trailing slash to distinguish directories.
172+
const pathFromMatcher = toPosixPath(relativePath);
173+
return rootMatcher.test(isDirectory ? `${pathFromMatcher}/` : pathFromMatcher).ignored;
174+
}
175+
167176
const segments = relativePath.split(path.sep);
168177
let directoryPath = this.#rootPath;
169178
let pathFromMatcher = segments.join('/');

0 commit comments

Comments
 (0)