Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

querystring: avoid indexOf when parsing #14703

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ function parse(qs, sep, eq, options) {
}
const customDecode = (decode !== qsUnescape);

const keys = [];
var lastPos = 0;
var sepIdx = 0;
var eqIdx = 0;
Expand Down Expand Up @@ -326,11 +325,8 @@ function parse(qs, sep, eq, options) {
if (value.length > 0 && valEncoded)
value = decodeStr(value, decode);

// Use a key array lookup instead of using hasOwnProperty(), which is
// slower
if (keys.indexOf(key) === -1) {
if (obj[key] === undefined) {
obj[key] = value;
keys[keys.length] = key;
} else {
const curValue = obj[key];
// A simple Array-specific property check is enough here to
Expand Down Expand Up @@ -428,10 +424,8 @@ function parse(qs, sep, eq, options) {
key = decodeStr(key, decode);
if (value.length > 0 && valEncoded)
value = decodeStr(value, decode);
// Use a key array lookup instead of using hasOwnProperty(), which is slower
if (keys.indexOf(key) === -1) {
if (obj[key] === undefined) {
obj[key] = value;
keys[keys.length] = key;
} else {
const curValue = obj[key];
// A simple Array-specific property check is enough here to
Expand Down