GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — querystring: simplify stringify method · windwiny/node@b965ac2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/querystring
    • querystring-stringify.js
  • lib
    • querystring.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/querystring/querystring-stringify.js‎

Copy file name to clipboardExpand all lines: benchmark/querystring/querystring-stringify.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const common = require('../common.js');
33
const querystring = require('querystring');
44

55
const bench = common.createBenchmark(main, {
6-
type: ['noencode', 'encodemany', 'encodelast'],
7-
n: [1e7],
6+
type: ['noencode', 'encodemany', 'encodelast', 'array'],
7+
n: [1e6],
88
});
99

1010
function main({ type, n }) {
@@ -23,6 +23,11 @@ function main({ type, n }) {
2323
foo: 'bar',
2424
baz: 'quux',
2525
xyzzy: 'thu\u00AC'
26+
},
27+
array: {
28+
foo: [],
29+
baz: ['bar'],
30+
xyzzy: ['bar', 'quux', 'thud']
2631
}
2732
};
2833
const input = inputs[type];
Collapse file

‎lib/querystring.js‎

Copy file name to clipboardExpand all lines: lib/querystring.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,19 @@ function stringify(obj, sep, eq, options) {
176176

177177
if (Array.isArray(v)) {
178178
var vlen = v.length;
179+
if (vlen === 0) continue;
179180
var vlast = vlen - 1;
180181
for (var j = 0; j < vlen; ++j) {
181182
fields += ks + encode(stringifyPrimitive(v[j]));
182183
if (j < vlast)
183184
fields += sep;
184185
}
185-
if (vlen && i < flast)
186-
fields += sep;
187186
} else {
188187
fields += ks + encode(stringifyPrimitive(v));
189-
if (i < flast)
190-
fields += sep;
191188
}
189+
190+
if (i < flast)
191+
fields += sep;
192192
}
193193
return fields;
194194
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.