From 3694fbcb09b62793cf6bd05040eb1169eca04d8c Mon Sep 17 00:00:00 2001 From: Phillip9587 Date: Fri, 3 Oct 2025 16:55:39 +0200 Subject: [PATCH] perf(urlencoded): move empty-body guard to avoid extra function closure --- lib/types/urlencoded.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/types/urlencoded.js b/lib/types/urlencoded.js index 4a3227c1..4b08631c 100644 --- a/lib/types/urlencoded.js +++ b/lib/types/urlencoded.js @@ -39,13 +39,7 @@ function urlencoded (options) { } // create the appropriate query parser - var queryparse = createQueryParser(options) - - function parse (body, encoding) { - return body.length - ? queryparse(body, encoding) - : {} - } + const parse = createQueryParser(options) const readOptions = { ...normalizedOptions, @@ -86,7 +80,9 @@ function createQueryParser (options) { parameterLimit = parameterLimit | 0 } - return function queryparse (body, encoding) { + return function parse (body, encoding) { + if (!body.length) return {} + var paramCount = parameterCount(body, parameterLimit) if (paramCount === undefined) {