Skip to content

Commit 5a10fe9

Browse files
Manuel Vallsrvagg
Manuel Valls
authored andcommitted
querystring: use String.prototype.split's limit
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]>
1 parent 58d67e2 commit 5a10fe9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/querystring.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,20 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
209209
return obj;
210210
}
211211

212-
qs = qs.split(sep);
213-
214212
var maxKeys = 1000;
215213
if (options && typeof options.maxKeys === 'number') {
216214
maxKeys = options.maxKeys;
217215
}
218216

219-
var len = qs.length;
220217
// maxKeys <= 0 means that we should not limit keys count
221-
if (maxKeys > 0 && len > maxKeys) {
222-
len = maxKeys;
218+
if (maxKeys > 0) {
219+
qs = qs.split(sep, maxKeys);
220+
} else {
221+
qs = qs.split(sep);
223222
}
224223

224+
var len = qs.length;
225+
225226
var decode = QueryString.unescape;
226227
if (options && typeof options.decodeURIComponent === 'function') {
227228
decode = options.decodeURIComponent;

0 commit comments

Comments
 (0)