Skip to content

Commit

Permalink
querystring: use String.prototype.split's limit
Browse files Browse the repository at this point in the history
There's no need to add extra logic for it, `String.prototype.split`
already has a `limit` argument. By using this argument we avoid keeping
the whole array in memory, and V8 doesn't have to process the entire
string.

PR-URL: #2288
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
  • Loading branch information
Manuel Valls authored and targos committed Jan 31, 2016
1 parent d2dc234 commit 27def4f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,20 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
return obj;
}

qs = qs.split(sep);

var maxKeys = 1000;
if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}

var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
if (maxKeys > 0) {
qs = qs.split(sep, maxKeys);
} else {
qs = qs.split(sep);
}

var len = qs.length;

var decode = QueryString.unescape;
if (options && typeof options.decodeURIComponent === 'function') {
decode = options.decodeURIComponent;
Expand Down

1 comment on commit 27def4f

@MylesBorins
Copy link
Contributor

Choose a reason for hiding this comment

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

fix for this landed in 878bcd4

Please sign in to comment.