Skip to content

Commit 438c216

Browse files
committed
docs: improve code comments
1 parent 9518413 commit 438c216

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] }))
4848
╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗
4949
║ Slower tests │ Samples │ Result │ Tolerance ║
5050
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
51-
║ qs │ 10000 │ 314822.82 op/sec │ ± 1.12 % ║
52-
║ query-string │ 1000 330364.46 op/sec │ ± 0.89 % ║
53-
║ querystringify │ 10000 442352.24 op/sec │ ± 1.31 % ║
54-
║ @aws-sdk/querystring-parser │ 10000 471561.65 op/sec │ ± 1.12 % ║
55-
║ URLSearchParams-with-Object.fromEntries │ 10000 │ 865453.19 op/sec │ ± 2.29 % ║
56-
║ URLSearchParams-with-construct │ 10000 │ 1234031.63 op/sec │ ± 3.12 % ║
57-
║ node:querystring │ 10000 │ 1484397.94 op/sec │ ± 2.46 % ║
51+
║ qs │ 10000 │ 317841.53 op/sec │ ± 1.18 % ║
52+
║ query-string │ 10000 341009.91 op/sec │ ± 1.06 % ║
53+
║ querystringify │ 1000 451609.79 op/sec │ ± 0.61 % ║
54+
║ @aws-sdk/querystring-parser │ 1000 477241.09 op/sec │ ± 0.69 % ║
55+
║ URLSearchParams-with-Object.fromEntries │ 10000 │ 870095.07 op/sec │ ± 3.29 % ║
56+
║ URLSearchParams-with-construct │ 10000 │ 1232650.60 op/sec │ ± 2.95 % ║
57+
║ node:querystring │ 10000 │ 1462802.04 op/sec │ ± 3.69 % ║
5858
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
5959
║ Fastest test │ Samples │ Result │ Tolerance ║
6060
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
61-
║ fast-querystring │ 10000 │ 1798615.82 op/sec │ ± 2.65 % ║
61+
║ fast-querystring │ 10000 │ 1809816.84 op/sec │ ± 3.19 % ║
6262
╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝
6363
```
6464

lib/parse.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ function parse(input) {
3535
if (c === 38 || c === -1) {
3636
hasBothKeyValuePair = equalityIndex > startingIndex;
3737
keyEndingIndex = hasBothKeyValuePair ? equalityIndex : i;
38-
3938
key = input.slice(startingIndex + 1, keyEndingIndex);
4039

41-
// Check if the current range consist of a single key
40+
// Only update value if '=' exists in the current range
4241
if (hasBothKeyValuePair) {
4342
value = input.slice(equalityIndex + 1, i);
4443
}
@@ -70,6 +69,7 @@ function parse(input) {
7069
} else {
7170
const currentValue = result[key];
7271

72+
// Optimization: value.pop is faster than Array.isArray(value)
7373
if (currentValue.pop) {
7474
currentValue.push(value);
7575
} else {
@@ -79,7 +79,6 @@ function parse(input) {
7979
}
8080

8181
// Reset reading key value pairs
82-
key = "";
8382
value = "";
8483
startingIndex = i;
8584
equalityIndex = i;
@@ -98,7 +97,7 @@ function parse(input) {
9897
equalityIndex = i;
9998
}
10099
}
101-
// Check '+', and replace it with empty space.
100+
// Check '+', and remember to replace it with empty space.
102101
else if (c === 43) {
103102
if (equalityIndex <= startingIndex) {
104103
keyHasPlus = true;

0 commit comments

Comments
 (0)