Skip to content
Permalink
Browse files
fix: Improve performance (#53)
  • Loading branch information
Trott committed Sep 29, 2021
1 parent 3ad3690 commit 843f8de1c177e9a5c06c4cfd2349ca5207168e00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
@@ -6,7 +6,6 @@ var isWin32 = require('os').platform() === 'win32';

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

/**
@@ -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');
@@ -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);
}
@@ -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",
@@ -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) {

0 comments on commit 843f8de

Please sign in to comment.