From c64258840a566977ea6b6957d6afeed3b8ca98a2 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Wed, 15 Dec 2021 10:47:35 -0600 Subject: [PATCH 1/3] fixing performance bug (see #64) in PHP implementation --- minify.json.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/minify.json.php b/minify.json.php index fcd5398..e11361e 100644 --- a/minify.json.php +++ b/minify.json.php @@ -1,7 +1,7 @@ \ No newline at end of file +?> From 8145afa1a5e17c3e542f1e96c37aca42efa4e103 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Wed, 15 Dec 2021 11:10:13 -0600 Subject: [PATCH 2/3] tweaking to just copy less string, which should give better perf --- minify.json.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/minify.json.php b/minify.json.php index e11361e..eb9277e 100644 --- a/minify.json.php +++ b/minify.json.php @@ -15,7 +15,8 @@ function json_minify($json) { while (preg_match($tokenizer,$json,$tmp,PREG_OFFSET_CAPTURE,$lastIndex)) { $tmp = $tmp[0]; $lastIndex = $tmp[1] + strlen($tmp[0]); - $lc = substr($json,0,$lastIndex - strlen($tmp[0])); + $prevFrom = $from; + $lc = substr($json,$prevFrom,$lastIndex - strlen($tmp[0])); $rc = substr($json,$lastIndex); if (!$in_multiline_comment && !$in_singleline_comment) { $tmp2 = substr($lc,$from); @@ -24,11 +25,10 @@ function json_minify($json) { } $new_str[] = $tmp2; } - $prevFrom = $from; $from = $lastIndex; if ($tmp[0] == "\"" && !$in_multiline_comment && !$in_singleline_comment) { - preg_match("/(\\\\)*$/",$lc,$tmp2,PREG_PATTERN_ORDER,$prevFrom); + preg_match("/(\\\\)*$/",$lc,$tmp2); if (!$in_string || !$tmp2 || (strlen($tmp2[0]) % 2) == 0) { // start of string with ", or unescaped " character found to end string $in_string = !$in_string; } From 46898e25f95c83cbdd9ae15934e69e47dd7b4ea4 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 21 Dec 2021 18:03:31 -0800 Subject: [PATCH 3/3] per #64, more performance tweaks --- minify.json.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/minify.json.php b/minify.json.php index eb9277e..b7f0378 100644 --- a/minify.json.php +++ b/minify.json.php @@ -1,7 +1,7 @@