Skip to content

Commit

Permalink
fix deopt
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jul 13, 2017
1 parent 7253d83 commit 2133d0b
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions index.js
Expand Up @@ -173,7 +173,7 @@ Router.prototype.find = function (method, path) {
// found the route
if (pathLen === 0 || path === prefix) {
var handle = currentNode.getHandler(method)
if (!handle) return null
if (handle === null) break

var paramNames = handle.params
var paramsObj = {}
Expand All @@ -193,7 +193,10 @@ Router.prototype.find = function (method, path) {
i = pathLen < prefixLen ? pathLen : prefixLen
while (len < i && path[len] === prefix[len]) len++

if (len === prefixLen) path = path.slice(len)
if (len === prefixLen) {
path = path.slice(len)
pathLen = path.length
}

node = currentNode.find(path[0])
if (!node) return null
Expand All @@ -202,53 +205,39 @@ Router.prototype.find = function (method, path) {
// static route
if (kind === 0) {
currentNode = node
continue
}

// parametric route
if (kind === 1) {
} else if (kind === 1) { // parametric route
currentNode = node
i = 0
while (i < pathLen && path.charCodeAt(i) !== 47) i++
decoded = fastDecode(path.slice(0, i))
for (; i < pathLen && path.charCodeAt(i) !== 47; i++) {}
decoded = fastDecode(path.substring(0, i))
if (errored) {
return null
break
}
params[pindex++] = decoded
path = path.slice(i)
continue
}

// wildcard route
if (kind === 2) {
path = path.substring(i)
} else if (kind === 2) { // wildcard route
decoded = fastDecode(path)
if (errored) {
return null
break
}
params[pindex] = decoded
currentNode = node
path = ''
continue
}

// parametric(regex) route
if (kind === 3) {
} else if (kind === 3) { // parametric(regex) route
currentNode = node
i = 0
while (i < pathLen && path.charCodeAt(i) !== 47) i++
for (; i < pathLen && path.charCodeAt(i) !== 47; i++) {}
decoded = fastDecode(path.slice(0, i))
if (errored) {
return null
break
}
if (!node.regex.test(decoded)) return
if (!node.regex.test(decoded)) break
params[pindex++] = decoded
path = path.slice(i)
continue
}

// route not found
if (len !== prefixLen) return null
} else if (len !== prefixLen) break // route not found
}

return null
}

Router.prototype._defaultRoute = function (req, res) {
Expand Down

0 comments on commit 2133d0b

Please sign in to comment.