Skip to content

Commit bc7e1a1

Browse files
committed
perf: improve stringify benchmarks
1 parent 1d5492c commit bc7e1a1

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

benchmark/stringify.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const value = {
88
frappucino: "muffin",
99
goat: "scone",
1010
pond: "moose",
11-
foo: ["bar", "baz"],
11+
foo: ["bar", "baz", "bal"],
12+
bool: true,
13+
bigIntKey: BigInt(100),
14+
numberKey: 256,
1215
};
1316

1417
await benchmark(

lib/internals/querystring.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ function encodeString(str) {
7171
// Surrogate pair
7272
++i;
7373

74-
// This branch should never happen because all URLSearchParams entries
75-
// should already be converted to USVString. But, included for
76-
// completion's sake anyway.
77-
if (i >= len) throw new Error("Invalid URI");
78-
7974
const c2 = str.charCodeAt(i) & 0x3FF;
8075

8176
lastPos = i + 1;

lib/stringify.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ function getAsPrimitive(value) {
88
if (type === "string") {
99
// Length check is handled inside encodeString function
1010
return encodeString(value);
11-
} else if (type === "number" && Number.isFinite(value)) {
12-
if (Math.abs(value) < 1e21) return value + "";
13-
return encodeString(value);
1411
} else if (type === "bigint") {
1512
return value + "";
1613
} else if (type === "boolean") {
1714
return value ? "true" : "false";
15+
} else if (type === "number" && Number.isFinite(value)) {
16+
if (Math.abs(value) < 1e21) return value + "";
17+
return encodeString(value + "");
1818
}
1919

2020
return "";

0 commit comments

Comments
 (0)