Skip to content

Commit

Permalink
Improves performance of glob exclusions by avoiding extra glob IO
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
cspotcode committed Nov 7, 2016
1 parent 1827423 commit 3c94d8b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/grunt/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3c94d8b

Please sign in to comment.