From 979510f70bb4dfeae6a8a9e018fb198850d85af5 Mon Sep 17 00:00:00 2001 From: EdamAmex <121654029+EdamAme-x@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:26:35 +0900 Subject: [PATCH] perf(pattern-router): improve performance when create null object (#3730) --- src/router/pattern-router/router.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/router/pattern-router/router.ts b/src/router/pattern-router/router.ts index d15610409..5f599471e 100644 --- a/src/router/pattern-router/router.ts +++ b/src/router/pattern-router/router.ts @@ -3,6 +3,8 @@ import { METHOD_NAME_ALL, UnsupportedPathError } from '../../router' type Route = [RegExp, string, T] // [pattern, method, handler, path] +const emptyParams = Object.create(null) + export class PatternRouter implements Router { name: string = 'PatternRouter' #routes: Route[] = [] @@ -46,7 +48,7 @@ export class PatternRouter implements Router { 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]) } } }