GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: add pattern cache for matchGlobPattern() · nodejs/node@e5af022

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/fs
    • glob.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/fs/glob.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/glob.js
+20-10Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ class Glob {
922922
}
923923
}
924924

925+
const kGlobPatternCacheLimit = 250;
926+
const patternFnCache = new SafeMap();
927+
925928
/**
926929
* Check if a path matches a glob pattern
927930
* @param {string} path the path to check
@@ -932,16 +935,23 @@ class Glob {
932935
function matchGlobPattern(path, pattern, windows = isWindows) {
933936
validateString(path, 'path');
934937
validateString(pattern, 'pattern');
935-
return lazyMinimatch().minimatch(path, pattern, {
936-
kEmptyObject,
937-
nocase: isMacOS || isWindows,
938-
windowsPathsNoEscape: true,
939-
nonegate: true,
940-
nocomment: true,
941-
optimizationLevel: 2,
942-
platform: windows ? 'win32' : 'posix',
943-
nocaseMagicOnly: true,
944-
});
938+
939+
let matcher;
940+
if (patternFnCache.has(pattern)) {
941+
matcher = patternFnCache.get(pattern);
942+
} else {
943+
matcher = createMatcher(pattern, {
944+
kEmptyObject,
945+
platform: windows ? 'win32' : 'posix',
946+
});
947+
patternFnCache.set(pattern, matcher);
948+
949+
if (patternFnCache.size >= kGlobPatternCacheLimit) {
950+
patternFnCache.delete(patternFnCache.keys().next().value);
951+
}
952+
}
953+
954+
return matcher.match(path);
945955
}
946956

947957
module.exports = {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.