Skip to content

Commit 5b791b4

Browse files
committed
fix: fix noLeftContext
1 parent 9a009c0 commit 5b791b4

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

Readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Minify JSON files **blazing fast**! Supports Comments. Written in D.
44

5-
60 times faster than jsonminify!
5+
360 times faster than jsonminify!
66

77
[![CI](https://github.com/aminya/minijson/actions/workflows/CI.yml/badge.svg)](https://github.com/aminya/minijson/actions/workflows/CI.yml)
88

@@ -88,9 +88,11 @@ minifyFiles(["file1.json", "file2.json"], true);
8888

8989
### Benchmarks
9090

91+
On AMD Ryzen 7 4800H:
92+
9193
```
9294
❯ node .\benchmark\native-benchmark.mjs
93-
0.977 seconds
95+
0.163 seconds
9496
9597
❯ node .\benchmark\js-benchmark.mjs
9698
58.818 seconds

src/native/lib.d

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ string minifyString(in string jsonString, in bool hasComment = false) @trusted
4646
if (noCommentOrNotInComment)
4747
{
4848
auto leftContextSubstr = match.pre()[prevFrom .. $];
49-
if (leftContextSubstr.length != 0)
49+
const noLeftContext = leftContextSubstr.length == 0;
50+
if (!in_string && !noLeftContext)
5051
{
51-
if (!in_string)
52-
{
53-
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
54-
}
52+
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
53+
}
54+
if (!noLeftContext) {
5555
result ~= leftContextSubstr;
56+
}
5657

57-
if (matchFrontHit == "\"")
58+
if (matchFrontHit == "\"")
59+
{
60+
if (!in_string || noLeftContext || hasNoSlashOrEvenNumberOfSlashes(leftContextSubstr))
5861
{
59-
if (!in_string || hasNoSlashOrEvenNumberOfSlashes(leftContextSubstr))
60-
{
61-
// start of string with ", or unescaped " character found to end string
62-
in_string = !in_string;
63-
}
64-
--from; // include " character in next catch
65-
rightContext = jsonString[from .. $];
62+
// start of string with ", or unescaped " character found to end string
63+
in_string = !in_string;
6664
}
65+
--from; // include " character in next catch
66+
rightContext = jsonString[from .. $];
6767
}
6868
}
6969
// comments

0 commit comments

Comments
 (0)