Skip to content

Commit d0e9739

Browse files
committed
perf: use fast-decode-uri-component for decoding
1 parent c6e16dc commit d0e9739

4 files changed

Lines changed: 20 additions & 20 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ console.log(qs)
4141
╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╤══════════════════════════╗
4242
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with previous ║
4343
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────┼──────────────────────────╢
44-
║ qs │ 10000 │ 314490.53 op/sec │ ± 1.30 % │ ║
45-
║ query-string │ 10000 │ 335943.68 op/sec │ ± 1.26 % │ + 6.82 % ║
46-
║ URLSearchParams-with-Object.fromEntries │ 10000 │ 841094.46 op/sec │ ± 2.71 % │ + 150.37 % ║
47-
║ URLSearchParams-with-construct │ 10000 │ 1230055.12 op/sec │ ± 3.04 % │ + 46.24 % ║
48-
║ node:querystring │ 10000 │ 1402133.99 op/sec │ ± 4.02 % │ + 13.99 % ║
44+
║ qs │ 10000 │ 295583.95 op/sec │ ± 1.44 % │ ║
45+
║ query-string │ 10000 │ 314370.91 op/sec │ ± 1.07 % │ + 6.36 % ║
46+
║ URLSearchParams-with-Object.fromEntries │ 10000 │ 808356.40 op/sec │ ± 2.45 % │ + 157.13 % ║
47+
║ URLSearchParams-with-construct │ 10000 │ 1135683.90 op/sec │ ± 3.18 % │ + 40.49 % ║
48+
║ node:querystring │ 10000 │ 1275958.09 op/sec │ ± 3.88 % │ + 12.35 % ║
4949
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────┼──────────────────────────╢
5050
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with previous ║
5151
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────┼──────────────────────────╢
52-
║ fast-querystring │ 10000 │ 1620376.82 op/sec │ ± 3.72 % │ + 15.57 % ║
52+
║ fast-querystring │ 10000 │ 1492040.49 op/sec │ ± 2.77 % │ + 16.93 % ║
5353
╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╧══════════════════════════╝
5454
```

lib/parse.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
"use strict";
22

3-
/**
4-
* @callback
5-
* @param {string} value
6-
* @returns {string}
7-
*/
8-
function decode(value) {
9-
try {
10-
return decodeURIComponent(value);
11-
} catch {
12-
return value;
13-
}
14-
}
3+
const fastDecode = require("fast-decode-uri-component");
154

165
/**
176
* @callback parse
@@ -59,8 +48,8 @@ function parse(input) {
5948

6049
// Optimization: Do not decode if it's not necessary.
6150
if (shouldDecode) {
62-
key = decode(key);
63-
value = decode(value);
51+
key = fastDecode(key) || key;
52+
value = fastDecode(value) || value;
6453
}
6554

6655
if (result[key] === undefined) {

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"repository": {
3131
"url": "git+https://github.com/anonrig/fast-querystring.git",
3232
"type": "git"
33+
},
34+
"dependencies": {
35+
"fast-decode-uri-component": "^1.0.1"
3336
}
3437
}

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)