Skip to content

Commit 080f007

Browse files
authored
Merge pull request dimdenGD#53 from cesco69/opt-2
perf: optimization
2 parents 5d5e595 + 3b17f93 commit 080f007

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/router.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ module.exports = class Router extends EventEmitter {
118118
}
119119
return pattern === path;
120120
}
121-
121+
if (pattern.source === '(?:)'){
122+
return true;
123+
}
122124
return pattern.test(path);
123125
}
124126

@@ -452,10 +454,11 @@ module.exports = class Router extends EventEmitter {
452454
const continueRoute = this._paramCallbacks.size === 0 && req.routeCount % 300 !== 0 ?
453455
this._preprocessRequest(req, res, route) : await this._preprocessRequest(req, res, route);
454456

457+
const strictRouting = this.get('strict routing');
455458
if(route.use) {
456-
const strictRouting = this.get('strict routing');
457459
req._stack.push(route.path);
458-
req._opPath = req._originalPath.replace(this.getFullMountpath(req), '');
460+
const fullMountpath = this.getFullMountpath(req);
461+
req._opPath = fullMountpath !== '' ? req._originalPath.replace(fullMountpath, '') : fullMountpath;
459462
if(req.endsWithSlash && req._opPath[req._opPath.length - 1] !== '/') {
460463
if(strictRouting) {
461464
req._opPath += '/';
@@ -476,7 +479,7 @@ module.exports = class Router extends EventEmitter {
476479
if(thingamabob === 'route' || thingamabob === 'skipPop') {
477480
if(route.use && thingamabob !== 'skipPop') {
478481
req._stack.pop();
479-
const strictRouting = this.get('strict routing');
482+
480483
req._opPath = req._stack.length > 0 ? req._originalPath.replace(this.getFullMountpath(req), '') : req._originalPath;
481484
if(strictRouting) {
482485
if(req.endsWithSlash && req._opPath[req._opPath.length - 1] !== '/') {

0 commit comments

Comments
 (0)