| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -922,6 +922,9 @@ class Glob { | |||
| 922 | 922 | } | |
| 923 | 923 | } | |
| 924 | 924 | ||
| 925 | + const kGlobPatternCacheLimit = 250; | ||
| 926 | + const patternFnCache = new SafeMap(); | ||
| 927 | + | ||
| 925 | 928 | /** | |
| 926 | 929 | * Check if a path matches a glob pattern | |
| 927 | 930 | * @param {string} path the path to check | |
@@ -932,16 +935,23 @@ class Glob { | |||
| 932 | 935 | function matchGlobPattern(path, pattern, windows = isWindows) { | |
| 933 | 936 | validateString(path, 'path'); | |
| 934 | 937 | 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); | ||
| 945 | 955 | } | |
| 946 | 956 | ||
| 947 | 957 | module.exports = { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments