Skip to content

Commit 144c271

Browse files
authored
perf: fast exit for empty string (#790)
Signed-off-by: francesco <francesco.bagnoli.69@gmail.com>
1 parent fedbb91 commit 144c271

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/serializer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ module.exports = class Serializer {
8989

9090
asString (str) {
9191
const len = str.length
92-
if (len < 42) {
92+
if (len === 0) {
93+
return '""'
94+
} else if (len < 42) {
9395
// magically escape strings for json
9496
// relying on their charCodeAt
9597
// everything below 32 needs JSON.stringify()

0 commit comments

Comments
 (0)