Skip to content

Commit e813cfa

Browse files
mcollinaaddaleax
authored andcommitted
querystring: avoid indexOf when parsing
Fixes a performance regression in body-parser with V8 6.0. Removes the use of an auxiliary array, and just query the object directly. PR-URL: #14703 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a813294 commit e813cfa

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

lib/querystring.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ function parse(qs, sep, eq, options) {
285285
}
286286
const customDecode = (decode !== qsUnescape);
287287

288-
const keys = [];
289288
var lastPos = 0;
290289
var sepIdx = 0;
291290
var eqIdx = 0;
@@ -326,11 +325,8 @@ function parse(qs, sep, eq, options) {
326325
if (value.length > 0 && valEncoded)
327326
value = decodeStr(value, decode);
328327

329-
// Use a key array lookup instead of using hasOwnProperty(), which is
330-
// slower
331-
if (keys.indexOf(key) === -1) {
328+
if (obj[key] === undefined) {
332329
obj[key] = value;
333-
keys[keys.length] = key;
334330
} else {
335331
const curValue = obj[key];
336332
// A simple Array-specific property check is enough here to
@@ -428,10 +424,8 @@ function parse(qs, sep, eq, options) {
428424
key = decodeStr(key, decode);
429425
if (value.length > 0 && valEncoded)
430426
value = decodeStr(value, decode);
431-
// Use a key array lookup instead of using hasOwnProperty(), which is slower
432-
if (keys.indexOf(key) === -1) {
427+
if (obj[key] === undefined) {
433428
obj[key] = value;
434-
keys[keys.length] = key;
435429
} else {
436430
const curValue = obj[key];
437431
// A simple Array-specific property check is enough here to

0 commit comments

Comments
 (0)