Skip to content

Commit

Permalink
Merge pull request #14 from aminya/perf
Browse files Browse the repository at this point in the history
perf: defer calculations until needed
  • Loading branch information
aminya authored Jul 7, 2021
2 parents 915acbf + aabd1aa commit 08bfaaa
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/native/lib.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,18 @@ string minifyString(string jsonString, bool hasComments = false) @trusted
{
const matchFrontHit = match.front().hit();

const leftContext = match.pre();
rightContext = match.post();

const lastIndex = jsonString.length - rightContext.length;

auto leftContextSubstr = leftContext[from .. $];

// update from for the next iteration
from = lastIndex;
const prevFrom = from;
from = jsonString.length - rightContext.length; // lastIndex

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

if (noCommentOrNotInComment)
{
auto leftContextSubstr = match.pre()[prevFrom .. $];

if (!in_string)
{
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
Expand Down

0 comments on commit 08bfaaa

Please sign in to comment.