diff options
author | Matteo Collina <hello@matteocollina.com> | 2017-08-09 00:41:52 +0200 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2017-08-09 14:03:48 -0400 |
commit | 7ec28a0a506efe9d1c03240fd028bea4a3d350da (patch) | |
tree | 8d380b60d69d641b2e79472274413e636c969e76 /lib/querystring.js | |
parent | 1e569f42b6950bfc24b9edaa135abc5b7a79d7f6 (diff) | |
download | android-node-v8-7ec28a0a506efe9d1c03240fd028bea4a3d350da.tar.gz android-node-v8-7ec28a0a506efe9d1c03240fd028bea4a3d350da.tar.bz2 android-node-v8-7ec28a0a506efe9d1c03240fd028bea4a3d350da.zip |
querystring: avoid indexOf when parsing
Fixes a performance regression in body-parser with V8 6.0.
Removes the use of an auxiliary array, and just query the object
directly.
PR-URL: https://github.com/nodejs/node/pull/14703
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib/querystring.js')
-rw-r--r-- | lib/querystring.js | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/querystring.js b/lib/querystring.js index 0eaaca57b0..b4851f57c3 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -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; @@ -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 @@ -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 |