Skip to content
Myr

perf: do not `compose` if it has only one handler (#493)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent be437ed · Browse files · 2 files+38 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+38 added−4 removed

  • other:+38 added−4 removed

2 files+38 added−4 removed

modified:deno_dist/hono.ts+19 added-2 removed
197 unmodified lines
198199 const result = this.matchRoute(method, path)200 request.paramData = result?.params201202 const handlers = result ? result.handlers : [this.notFoundHandler]203202 const c = new HonoContext<string, E>(request, env, eventOrExecutionCtx, this.notFoundHandler)203204 // Do not `compose` if it has only one handler205 if (result && result.handlers.length === 1) {206 const handler = result.handlers[0]207 try {208 const response = handler(c, async () => {})209 if (response) {210 if (response instanceof Promise) {211 const awaited = await response212 if (awaited) return awaited213 } else {214 return response215 }216 }217 // Do nothing218 } catch {}219 }220221 const handlers = result ? result.handlers : [this.notFoundHandler]222223 const composed = compose<HonoContext<string, E>>(handlers, this.notFoundHandler)224 let context: HonoContext<string, E>225 try {226 context = await composed(c)
28 unmodified lines
modified:src/hono.ts+19 added-2 removed
197 unmodified lines
198199 const result = this.matchRoute(method, path)200 request.paramData = result?.params201202 const handlers = result ? result.handlers : [this.notFoundHandler]203202 const c = new HonoContext<string, E>(request, env, eventOrExecutionCtx, this.notFoundHandler)203204 // Do not `compose` if it has only one handler205 if (result && result.handlers.length === 1) {206 const handler = result.handlers[0]207 try {208 const response = handler(c, async () => {})209 if (response) {210 if (response instanceof Promise) {211 const awaited = await response212 if (awaited) return awaited213 } else {214 return response215 }216 }217 // Do nothing218 } catch {}219 }220221 const handlers = result ? result.handlers : [this.notFoundHandler]222223 const composed = compose<HonoContext<string, E>>(handlers, this.notFoundHandler)224 let context: HonoContext<string, E>225 try {226 context = await composed(c)
28 unmodified lines