Skip to content

Commit

Permalink
perf: add fast match path for "*" route
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 26, 2017
1 parent 1f71fae commit 081b811
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ unreleased
- Use `res.getHeaderNames()` when available
- Use `res.headersSent` when available
- deps: [email protected]
* perf: add fast match path for `*` route
* perf: improve `req.ips` performance

4.14.1 / 2017-01-28
Expand Down
15 changes: 11 additions & 4 deletions lib/router/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function Layer(path, options, fn) {
this.path = undefined;
this.regexp = pathRegexp(path, this.keys = [], opts);

if (path === '/' && opts.end === false) {
this.regexp.fast_slash = true;
}
// set fast path flags
this.regexp.fast_star = path === '*'
this.regexp.fast_slash = path === '/' && opts.end === false
}

/**
Expand Down Expand Up @@ -111,13 +111,20 @@ Layer.prototype.match = function match(path) {
var match

if (path != null) {
// fast path non-ending match for / (any path matches)
if (this.regexp.fast_slash) {
// fast path non-ending match for / (everything matches)
this.params = {}
this.path = ''
return true
}

// fast path for * (everything matched in a param)
if (this.regexp.fast_star) {
this.params = {'0': decode_param(path)}
this.path = path
return true
}

// match the path
match = this.regexp.exec(path)
}
Expand Down

0 comments on commit 081b811

Please sign in to comment.