Skip to content

Commit

Permalink
perf(pattern-router): improve performance when create null object (#3730
Browse files Browse the repository at this point in the history
)
  • Loading branch information
EdamAme-x authored Dec 9, 2024
1 parent 50ff212 commit 979510f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/router/pattern-router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { METHOD_NAME_ALL, UnsupportedPathError } from '../../router'

type Route<T> = [RegExp, string, T] // [pattern, method, handler, path]

const emptyParams = Object.create(null)

export class PatternRouter<T> implements Router<T> {
name: string = 'PatternRouter'
#routes: Route<T>[] = []
Expand Down Expand Up @@ -46,7 +48,7 @@ export class PatternRouter<T> implements Router<T> {
if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
const match = pattern.exec(path)
if (match) {
handlers.push([handler, match.groups || Object.create(null)])
handlers.push([handler, match.groups || emptyParams])
}
}
}
Expand Down

0 comments on commit 979510f

Please sign in to comment.