Skip to content

Commit f15a845

Browse files
committed
perf: merge the if conditions
1 parent 6f33d71 commit f15a845

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ minifyFiles(["file1.json", "file2.json"]);
7070

7171
```
7272
❯ node .\benchmark\native-benchmark.mjs
73-
1.086 seconds
73+
1.066 seconds
7474
7575
❯ node .\benchmark\js-benchmark.mjs
7676
58.686 seconds

src/native/lib.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ string minifyString(string jsonString, bool hasComments = false) @trusted
4242

4343
const lastIndex = jsonString.length - rightContext.length;
4444

45+
auto leftContextSubstr = leftContext[from .. $];
46+
47+
// update from for the next iteration
48+
from = lastIndex;
49+
4550
const noCommentOrNotInComment = !hasComments || (!in_multiline_comment && !in_singleline_comment);
4651

47-
auto leftContextSubstr = leftContext[from .. $];
4852
if (noCommentOrNotInComment)
4953
{
5054
if (!in_string)
5155
{
5256
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
5357
}
5458
new_str ~= leftContextSubstr;
55-
}
56-
from = lastIndex;
5759

58-
if (noCommentOrNotInComment)
59-
{
6060
if (matchFrontHit == "\"")
6161
{
6262
if (!in_string || hasNoSlashOrEvenNumberOfSlashes(leftContextSubstr))

test/fixtures/escaped_quote.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"a": "\" a "
2+
"a": "\" a ",
3+
"b": "\\\" a ",
4+
"c": "\\\\\" a ",
5+
"d": "a\\\\\\",
6+
"e": "\\\\\\"
37
}

0 commit comments

Comments
 (0)