Skip to content

Commit aabd1aa

Browse files
committed
perf: defer calculations until needed
1 parent 915acbf commit aabd1aa

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/native/lib.d

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,18 @@ string minifyString(string jsonString, bool hasComments = false) @trusted
3737
{
3838
const matchFrontHit = match.front().hit();
3939

40-
const leftContext = match.pre();
4140
rightContext = match.post();
4241

43-
const lastIndex = jsonString.length - rightContext.length;
44-
45-
auto leftContextSubstr = leftContext[from .. $];
46-
4742
// update from for the next iteration
48-
from = lastIndex;
43+
const prevFrom = from;
44+
from = jsonString.length - rightContext.length; // lastIndex
4945

5046
const noCommentOrNotInComment = !hasComments || (!in_multiline_comment && !in_singleline_comment);
5147

5248
if (noCommentOrNotInComment)
5349
{
50+
auto leftContextSubstr = match.pre()[prevFrom .. $];
51+
5452
if (!in_string)
5553
{
5654
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");

0 commit comments

Comments
 (0)