Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Apr 10, 2015
1 parent 75c92a5 commit 9e7f2d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
17 changes: 8 additions & 9 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var Node = (function () {
var l = this.edges.length;
var e = void 0;

for (; i < l; i++) {
for (; i < l; ++i) {
e = this.edges[i];
// compare charCode
if (e.label === c) return e;
Expand Down Expand Up @@ -64,15 +64,16 @@ var Router = (function () {

var i = 0,
l = path.length;
var ch = undefined;
for (; i < l; ++i) {
// `:`
if (path.charCodeAt(i) === 58) {
ch = path.charCodeAt(i);
if (ch === 58 /*':'*/) {
// param start index
var j = i + 1;
count++;

this.insert(method, path.substring(0, i), null, PNODE);
// `/`
// 47,`/`
for (; i < l && path.charCodeAt(i) !== 47; ++i) {}

// new param key `$n`
Expand All @@ -91,8 +92,7 @@ var Router = (function () {
return;
}
this.insert(method, path.substring(0, i), null, 0);
// `*`
} else if (path.charCodeAt(i) === 42) {
} else if (ch === 42 /*'*'*/) {
this.insert(method, path.substring(0, i), null, CNODE);
this.insert(method, path.substring(0, l), handler, 0);
}
Expand Down Expand Up @@ -192,12 +192,11 @@ var Router = (function () {
e = undefined;
for (; i < k; ++i) {
e = cn.edges[i];
var has = e.label === 58 ? PNODE : e.label === 42 ? CNODE : 0;
var has = e.label === 58 /*':'*/ ? PNODE : e.label === 42 /*'*'*/ ? CNODE : 0;
if (has === PNODE) {
l = search.length;
// `/`
var j = 0;
for (; j < l && search.charCodeAt(j) !== 47; ++j) {}
for (; j < l && search.charCodeAt(j) !== 47 /*'/'*/; ++j) {}

params[n] = {
name: e.prefix.substring(1),
Expand Down
19 changes: 9 additions & 10 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Node {

findEdge(c) {
let [i, l, e] = [0, this.edges.length, void 0];
for (; i < l; i++) {
for (; i < l; ++i) {
e = this.edges[i];
// compare charCode
if (e.label === c) return e;
Expand All @@ -60,16 +60,17 @@ class Router {
if (handler) handler.keys = keys;

let i = 0, l = path.length;
let ch;
for (; i < l; ++i) {
// `:`
if (path.charCodeAt(i) === 58) {
ch = path.charCodeAt(i);
if (ch === 0x3A /*':'*/) {
// param start index
let j = i + 1;
count++;

this.insert(method, path.substring(0, i), null, PNODE);
// `/`
for (; i < l && (path.charCodeAt(i) !== 47); ++i) {}
// 47,`/`
for (; i < l && (path.charCodeAt(i) !== 0x2F); ++i) {}

// new param key `$n`
let param = '$' + count;
Expand All @@ -87,8 +88,7 @@ class Router {
return;
}
this.insert(method, path.substring(0, i), null, 0);
// `*`
} else if (path.charCodeAt(i) === 42) {
} else if (ch === 0x2A /*'*'*/) {
this.insert(method, path.substring(0, i), null, CNODE);
this.insert(method, path.substring(0, l), handler, 0);
}
Expand Down Expand Up @@ -180,12 +180,11 @@ class Router {
let i = 0, k = cn.edges.length, e;
for (; i < k; ++i) {
e = cn.edges[i];
let has = e.label === 58 ? PNODE : (e.label === 42 ? CNODE : 0);
let has = e.label === 0x3A /*':'*/ ? PNODE : (e.label === 0x2A /*'*'*/ ? CNODE : 0);
if (has === PNODE) {
l = search.length;
// `/`
let j = 0;
for (; j < l && (search.charCodeAt(j) !== 47); ++j) {}
for (; j < l && (search.charCodeAt(j) !== 0x2F /*'/'*/); ++j) {}

params[n] = {
name: e.prefix.substring(1),
Expand Down

0 comments on commit 9e7f2d6

Please sign in to comment.