diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-06 23:08:42 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-18 15:25:39 +0200 |
commit | d0bb9b12051fa3540387a4c23d1f004b9d9a5a01 (patch) | |
tree | 5fe275ef872daf9c534ccd923d3f49418097dd25 /lib/url.js | |
parent | f4f8b22f7d474a9206ce1253cf884b94552759f3 (diff) | |
download | android-node-v8-d0bb9b12051fa3540387a4c23d1f004b9d9a5a01.tar.gz android-node-v8-d0bb9b12051fa3540387a4c23d1f004b9d9a5a01.tar.bz2 android-node-v8-d0bb9b12051fa3540387a4c23d1f004b9d9a5a01.zip |
querystring: lazy loaded
PR-URL: https://github.com/nodejs/node/pull/20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib/url.js')
-rw-r--r-- | lib/url.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/url.js b/lib/url.js index e4326e80b5..c517ba7ab3 100644 --- a/lib/url.js +++ b/lib/url.js @@ -94,7 +94,6 @@ const slashedProtocol = { 'file': true, 'file:': true }; -const querystring = require('querystring'); const { CHAR_SPACE, CHAR_TAB, @@ -133,6 +132,9 @@ const { CHAR_AT, } = require('internal/constants'); +// Lazy loaded for startup performance. +let querystring; + function urlParse(url, parseQueryString, slashesDenoteHost) { if (url instanceof Url) return url; @@ -233,6 +235,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { if (simplePath[2]) { this.search = simplePath[2]; if (parseQueryString) { + if (querystring === undefined) querystring = require('querystring'); this.query = querystring.parse(this.search.slice(1)); } else { this.query = this.search.slice(1); @@ -422,6 +425,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { this.query = rest.slice(questionIdx + 1, hashIdx); } if (parseQueryString) { + if (querystring === undefined) querystring = require('querystring'); this.query = querystring.parse(this.query); } } else if (parseQueryString) { @@ -584,8 +588,10 @@ Url.prototype.format = function format() { } } - if (this.query !== null && typeof this.query === 'object') + if (this.query !== null && typeof this.query === 'object') { + if (querystring === undefined) querystring = require('querystring'); query = querystring.stringify(this.query); + } var search = this.search || (query && ('?' + query)) || ''; |