Skip to content

Commit

Permalink
fix: Improve performance (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott authored Sep 29, 2021
1 parent 3ad3690 commit 843f8de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var isWin32 = require('os').platform() === 'win32';

var slash = '/';
var backslash = /\\/g;
var globby = /(^|[^\\])([{[]|\([^)]+$)/;
var escaped = /\\([!*?|[\](){}])/g;

/**
Expand All @@ -33,7 +32,7 @@ module.exports = function globParent(str, opts) {
// remove path parts that are globby
do {
str = pathPosixDirname(str);
} while (isGlob(str) || globby.test(str));
} while (isGlobby(str));

// remove escape chars and return result
return str.replace(escaped, '$1');
Expand Down Expand Up @@ -61,3 +60,16 @@ function isEnclosure(str) {

return str.slice(foundIndex + 1, -1).includes(slash);
}

function isGlobby(str) {
if (/\([^()]+$/.test(str)) {
return true;
}
if (str[0] === '{' || str[0] === '[') {
return true;
}
if (/[^\\][{[]/.test(str)) {
return true;
}
return isGlob(str);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test": "nyc mocha --async-only"
},
"dependencies": {
"is-glob": "^4.0.1"
"is-glob": "^4.0.3"
},
"devDependencies": {
"eslint": "^7.0.0",
Expand Down
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ describe('glob2base test patterns', function () {
gp('('.repeat(500000));
done();
});

it("should finish in reasonable time for '/('.repeat(n) + ')'", function (done) {
this.timeout(1000);
gp('/('.repeat(500000) + ')');
done();
});
});

if (isWin32) {
Expand Down

0 comments on commit 843f8de

Please sign in to comment.