fs: improve globSync performance

PR-URL: https://github.com/nodejs/node/pull/57725
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Rich Trott
2025-04-07 15:15:02 -07:00
committed by GitHub
parent 1f7cfb7a36
commit b2ab1a2c41

View File

@@ -331,10 +331,7 @@ class Glob {
const fullpath = resolve(this.#root, path);
// If path is a directory, add trailing slash and test patterns again.
// TODO(Trott): Would running #isExcluded() first and checking isDirectory() only
// if it matches be more performant in the typical use case? #isExcluded()
// is often ()=>false which is about as optimizable as a function gets.
if (this.#cache.statSync(fullpath).isDirectory() && this.#isExcluded(`${fullpath}/`)) {
if (this.#isExcluded(`${fullpath}/`) && this.#cache.statSync(fullpath).isDirectory()) {
return;
}