Skip to content

Commit 979510f

Browse files
authored
perf(pattern-router): improve performance when create null object (#3730)
1 parent 50ff212 commit 979510f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/router/pattern-router/router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { METHOD_NAME_ALL, UnsupportedPathError } from '../../router'
33

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

6+
const emptyParams = Object.create(null)
7+
68
export class PatternRouter<T> implements Router<T> {
79
name: string = 'PatternRouter'
810
#routes: Route<T>[] = []
@@ -46,7 +48,7 @@ export class PatternRouter<T> implements Router<T> {
4648
if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
4749
const match = pattern.exec(path)
4850
if (match) {
49-
handlers.push([handler, match.groups || Object.create(null)])
51+
handlers.push([handler, match.groups || emptyParams])
5052
}
5153
}
5254
}

0 commit comments

Comments
 (0)