Skip to content

Commit 843f8de

Browse files
authored
fix: Improve performance (#53)
1 parent 3ad3690 commit 843f8de

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var isWin32 = require('os').platform() === 'win32';
66

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

1211
/**
@@ -33,7 +32,7 @@ module.exports = function globParent(str, opts) {
3332
// remove path parts that are globby
3433
do {
3534
str = pathPosixDirname(str);
36-
} while (isGlob(str) || globby.test(str));
35+
} while (isGlobby(str));
3736

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

6261
return str.slice(foundIndex + 1, -1).includes(slash);
6362
}
63+
64+
function isGlobby(str) {
65+
if (/\([^()]+$/.test(str)) {
66+
return true;
67+
}
68+
if (str[0] === '{' || str[0] === '[') {
69+
return true;
70+
}
71+
if (/[^\\][{[]/.test(str)) {
72+
return true;
73+
}
74+
return isGlob(str);
75+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test": "nyc mocha --async-only"
2424
},
2525
"dependencies": {
26-
"is-glob": "^4.0.1"
26+
"is-glob": "^4.0.3"
2727
},
2828
"devDependencies": {
2929
"eslint": "^7.0.0",

test/index.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ describe('glob2base test patterns', function () {
242242
gp('('.repeat(500000));
243243
done();
244244
});
245+
246+
it("should finish in reasonable time for '/('.repeat(n) + ')'", function (done) {
247+
this.timeout(1000);
248+
gp('/('.repeat(500000) + ')');
249+
done();
250+
});
245251
});
246252

247253
if (isWin32) {

0 commit comments

Comments
 (0)