Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,11 @@ func (app *App) init() *App {
// error handler. Otherwise, it uses the configured error handler for
// the app, which if not set is the DefaultErrorHandler.
func (app *App) ErrorHandler(ctx Ctx, err error) error {
// Fast path: no mounted sub-apps, so no prefix lookup is needed
if len(app.mountFields.appListKeys) == 0 {
return app.config.ErrorHandler(ctx, err)
}

var (
mountedErrHandler ErrorHandler
mountedPrefixParts int
Expand Down
5 changes: 3 additions & 2 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,12 @@ func (c *DefaultCtx) ViewBind(vars Map) error {
// Route returns the matched Route struct.
func (c *DefaultCtx) Route() *Route {
if c.route == nil {
// Fallback for fasthttp error handler
// Fallback for fasthttp error handler; equals c.Method() without
// the variadic call so Route stays within the inlining budget
return &Route{
path: c.pathOriginal,
Path: c.pathOriginal,
Method: c.Method(),
Method: c.app.method(c.methodInt),
Handlers: emptyRouteHandlers[:],
Params: emptyRouteParams[:],
}
Expand Down
3 changes: 2 additions & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,10 @@ func (parser *routeParser) getMatch(detectionPath, path string, params *[maxPara
i = segment.Length
// is optional part or the const part must match with the given string
// check if the end of the segment is an optional slash
// the unsigned compare proves 0 <= i <= len(detectionPath), keeping detectionPath[:i] bounds-check free
if segment.HasOptionalSlash && partLen == i-1 && detectionPath == segment.Const[:i-1] {
i--
} else if i > partLen || detectionPath[:i] != segment.Const {
} else if uint(i) > uint(len(detectionPath)) || detectionPath[:i] != segment.Const {
return false
}
} else {
Expand Down
24 changes: 8 additions & 16 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,11 @@ func (app *App) next(c *DefaultCtx) (bool, error) {
if !ok {
tree = app.treeStack[methodInt][0]
}
lenr := len(tree) - 1

indexRoute := c.indexRoute

// Loop over the route stack starting from previous index
for indexRoute < lenr {
// Increment route index
indexRoute++
indexRoute := max(c.indexRoute+1, 0)

// Loop over the route stack starting from previous index;
// the clamp above plus the len(tree) guard keep tree[indexRoute] bounds-check free
for ; indexRoute < len(tree); indexRoute++ {
// Get *Route
route := tree[indexRoute]

Expand Down Expand Up @@ -337,15 +333,11 @@ func (app *App) nextCustom(c CustomCtx) (bool, error) {
if !ok {
tree = app.treeStack[methodInt][0]
}
lenr := len(tree) - 1

indexRoute := c.getIndexRoute()

// Loop over the route stack starting from previous index
for indexRoute < lenr {
// Increment route index
indexRoute++
indexRoute := max(c.getIndexRoute()+1, 0)

// Loop over the route stack starting from previous index;
// the clamp above plus the len(tree) guard keep tree[indexRoute] bounds-check free
for ; indexRoute < len(tree); indexRoute++ {
// Get *Route
route := tree[indexRoute]

Expand Down
Loading