diff --git a/Readme.md b/Readme.md index 130e349..660f28e 100644 --- a/Readme.md +++ b/Readme.md @@ -70,7 +70,7 @@ minifyFiles(["file1.json", "file2.json"]); ``` ❯ node .\benchmark\native-benchmark.mjs -1.086 seconds +1.066 seconds ❯ node .\benchmark\js-benchmark.mjs 58.686 seconds diff --git a/src/native/lib.d b/src/native/lib.d index 3c9a324..89a611f 100644 --- a/src/native/lib.d +++ b/src/native/lib.d @@ -42,9 +42,13 @@ string minifyString(string jsonString, bool hasComments = false) @trusted const lastIndex = jsonString.length - rightContext.length; + auto leftContextSubstr = leftContext[from .. $]; + + // update from for the next iteration + from = lastIndex; + const noCommentOrNotInComment = !hasComments || (!in_multiline_comment && !in_singleline_comment); - auto leftContextSubstr = leftContext[from .. $]; if (noCommentOrNotInComment) { if (!in_string) @@ -52,11 +56,7 @@ string minifyString(string jsonString, bool hasComments = false) @trusted leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, ""); } new_str ~= leftContextSubstr; - } - from = lastIndex; - if (noCommentOrNotInComment) - { if (matchFrontHit == "\"") { if (!in_string || hasNoSlashOrEvenNumberOfSlashes(leftContextSubstr)) diff --git a/test/fixtures/escaped_quote.json b/test/fixtures/escaped_quote.json index 5818377..e4b5440 100644 --- a/test/fixtures/escaped_quote.json +++ b/test/fixtures/escaped_quote.json @@ -1,3 +1,7 @@ { - "a": "\" a " + "a": "\" a ", + "b": "\\\" a ", + "c": "\\\\\" a ", + "d": "a\\\\\\", + "e": "\\\\\\" }