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

speedup array work by using push instead of concat #185

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/parse.js
Expand Up @@ -32,8 +32,14 @@ var parseValues = function parseValues(str, options) {
key = options.decoder(part.slice(0, pos));
val = options.decoder(part.slice(pos + 1));
}

if (has.call(obj, key)) {
obj[key] = [].concat(obj[key]).concat(val);
var cur = obj[key];
if (Array.isArray(cur)) {
cur.push(val);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also worth noting that this behaves differently when val is an array or not, because of the concat behavior. Since the decoder can be user-provided, it becomes very important to retain that auto-spreading behavior (as well as the lack of mutation).

} else {
obj[key] = [cur, val];
}
} else {
obj[key] = val;
}
Expand Down