Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a92da1

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
querystring: lazy loaded
PR-URL: #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>
1 parent 0ace8f9 commit 4a92da1
Copy full SHA for 4a92da1

File tree

Expand file treeCollapse file tree

2 files changed

+14
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const {
2727
CHAR_LOWERCASE_A,
2828
CHAR_LOWERCASE_Z,
2929
} = require('internal/constants');
30-
const querystring = require('querystring');
30+
31+
// Lazy loaded for startup performance.
32+
let querystring;
3133

3234
const { platform } = process;
3335
const isWindows = platform === 'win32';
@@ -771,8 +773,10 @@ function parseParams(qs) {
771773
} else if (encodeCheck > 0) {
772774
// eslint-disable-next-line no-extra-boolean-cast
773775
if (!!isHexTable[code]) {
774-
if (++encodeCheck === 3)
776+
if (++encodeCheck === 3) {
777+
querystring = require('querystring');
775778
encoded = true;
779+
}
776780
} else {
777781
encodeCheck = 0;
778782
}
Collapse file

‎lib/url.js‎

Copy file name to clipboardExpand all lines: lib/url.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ const slashedProtocol = {
9494
'file': true,
9595
'file:': true
9696
};
97-
const querystring = require('querystring');
9897
const {
9998
CHAR_SPACE,
10099
CHAR_TAB,
@@ -133,6 +132,9 @@ const {
133132
CHAR_AT,
134133
} = require('internal/constants');
135134

135+
// Lazy loaded for startup performance.
136+
let querystring;
137+
136138
function urlParse(url, parseQueryString, slashesDenoteHost) {
137139
if (url instanceof Url) return url;
138140

@@ -233,6 +235,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
233235
if (simplePath[2]) {
234236
this.search = simplePath[2];
235237
if (parseQueryString) {
238+
if (querystring === undefined) querystring = require('querystring');
236239
this.query = querystring.parse(this.search.slice(1));
237240
} else {
238241
this.query = this.search.slice(1);
@@ -422,6 +425,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
422425
this.query = rest.slice(questionIdx + 1, hashIdx);
423426
}
424427
if (parseQueryString) {
428+
if (querystring === undefined) querystring = require('querystring');
425429
this.query = querystring.parse(this.query);
426430
}
427431
} else if (parseQueryString) {
@@ -584,8 +588,10 @@ Url.prototype.format = function format() {
584588
}
585589
}
586590

587-
if (this.query !== null && typeof this.query === 'object')
591+
if (this.query !== null && typeof this.query === 'object') {
592+
if (querystring === undefined) querystring = require('querystring');
588593
query = querystring.stringify(this.query);
594+
}
589595

590596
var search = this.search || (query && ('?' + query)) || '';
591597

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.