summaryrefslogtreecommitdiff
path: root/lib/querystring.js
diff options
context:
space:
mode:
authorManuel Valls <manolo@vlrz.es>2015-11-17 08:28:04 +0100
committerMichaël Zasso <mic.besace@gmail.com>2016-01-31 17:30:06 +0100
commit27def4faf2fb0c759b7e8800f91627cbbca5fdba (patch)
tree50528d5a94dea43f35fc9f2bd78463d91841dc67 /lib/querystring.js
parentd2dc234def9f17b53abdafb38569a9f03057770e (diff)
downloadandroid-node-v8-27def4faf2fb0c759b7e8800f91627cbbca5fdba.tar.gz
android-node-v8-27def4faf2fb0c759b7e8800f91627cbbca5fdba.tar.bz2
android-node-v8-27def4faf2fb0c759b7e8800f91627cbbca5fdba.zip
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: https://github.com/nodejs/node/pull/2288 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Diffstat (limited to 'lib/querystring.js')
-rw-r--r--lib/querystring.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/querystring.js b/lib/querystring.js
index b034635668..d5d4f175b6 100644
--- a/lib/querystring.js
+++ b/lib/querystring.js
@@ -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;