From 3c94d8b3e6bdf9fb3ddbcff2da96c7184648c398 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 7 Nov 2016 13:45:27 -0500 Subject: [PATCH] Improves performance of glob exclusions by avoiding extra glob IO - IO is not necessary for exclusions because they exclude file paths that have already been discovered. Using `file.match` / `minimatch` is sufficient. - adds optional `excludeFn` callback to `processPatterns`. If provided, it will be called instead of `fn` for exclusion patterns. --- lib/grunt/file.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/grunt/file.js b/lib/grunt/file.js index 4efd838d0..aa80c5714 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -38,7 +38,8 @@ file.setBase = function() { // Process specified wildcard glob patterns or filenames against a // callback, excluding and uniquing files in the result set. -var processPatterns = function(patterns, fn) { +var processPatterns = function(patterns, fn, exclusionFn) { + if (typeof exclusionFn === 'undefined') { exclusionFn = fn; } // Filepaths to return. var result = []; // Iterate over flattened patterns array. @@ -48,7 +49,7 @@ var processPatterns = function(patterns, fn) { // If the pattern is an exclusion, remove the ! if (exclusion) { pattern = pattern.slice(1); } // Find all matching files for this pattern. - var matches = fn(pattern); + var matches = (exclusion ? exclusionFn : fn)(pattern, result); if (exclusion) { // If an exclusion, remove matching files. result = grunt.util._.difference(result, matches); @@ -104,6 +105,8 @@ file.expand = function() { var matches = processPatterns(patterns, function(pattern) { // Find all matching files for this pattern. return file.glob.sync(pattern, globOptions); + }, function(pattern, resultsThusFar) { + return file.match(options, [pattern], resultsThusFar); }); // Filter result set? if (options.filter) {