Skip to content

Commit

Permalink
fix recent find() changes; regain performance
Browse files Browse the repository at this point in the history
- back to 9.3M op/s from 6.0 op/s 🎉
  • Loading branch information
lukeed committed May 2, 2018
1 parent 554e156 commit e14c418
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ class Trouter {
}

find(method, url) {
let i=0, k, arr, keys=[method, '*'];
for (; i < keys.length; i++) {
k=keys[i]; arr=this.routes[k];
if (arr === void 0) continue;
arr = match(url, arr);
if (!arr.length) continue;
return {
params: exec(url, arr),
handler: this.handlers[k][arr[0].old]
};
let arr = match(url, this.routes[method] || []);
if (arr.length === 0) {
arr = match(url, this.routes[method='*'] || []);
if (!arr.length) return false;
}
return false;
return {
params: exec(url, arr),
handler: this.handlers[method][arr[0].old]
};
}
}

Expand Down

0 comments on commit e14c418

Please sign in to comment.