0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-22 02:27:49 +01:00

perf(router): sort handlers by score only when necessary

This commit is contained in:
Ame_x Edam 2024-11-21 06:30:36 +00:00
parent 44a50bdf55
commit a6beddb34a

View File

@ -198,10 +198,13 @@ export class Node<T> {
curNodes = tempNodes
}
const results = handlerSets.sort((a, b) => {
return a.score - b.score
})
return [results.map(({ handler, params }) => [handler, params] as [T, Params])]
if (handlerSets.length > 1) {
handlerSets.sort((a, b) => {
return a.score - b.score
})
}
return [handlerSets.map(({ handler, params }) => [handler, params] as [T, Params])]
}
}