From d10f2595de45aa39dd347aee6c7e164e06600e9a Mon Sep 17 00:00:00 2001 From: JasWSInc Date: Sun, 21 Sep 2014 22:28:23 -0800 Subject: [PATCH] Optimize regex. --- html-compressor/includes/core.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/html-compressor/includes/core.php b/html-compressor/includes/core.php index 54131a8..918d634 100644 --- a/html-compressor/includes/core.php +++ b/html-compressor/includes/core.php @@ -414,6 +414,7 @@ protected function maybe_compress_combine_head_js($html) if(($head_frag = $this->get_head_frag($html)) /* No need to get the HTML frag here; we're operating on the `` only. */) if(($js_tag_frags = $this->get_js_tag_frags($head_frag)) && ($js_parts = $this->compile_js_tag_frags_into_parts($js_tag_frags))) { + print_r($js_tag_frags); $js_tag_frags_all_compiled = $this->compile_key_elements_deep($js_tag_frags, 'all'); $html = $this->replace_once($head_frag['all'], '%%htmlc-head%%', $html); $cleaned_head_contents = $this->replace_once($js_tag_frags_all_compiled, '', $head_frag['contents']); @@ -804,8 +805,8 @@ protected function get_css_tag_frags(array $html_frag) $regex = '/(?P'. // Entire match. '(?P\<\![^[>]*?\[if\W[^\]]*?\][^>]*?\>\s*)?'. - '(?:(?P\]*?)?\>)'. // Or a tag. - '|(?P\]*?)?\>)(?P.*?)(?P\<\/style\>))'. + '(?:(?P\]*?)?\>)'. // Or a tag. + '|(?P\]*?)?\>)(?P.*?)(?P\<\/style\>))'. '(?P\s*\<\![^[>]*?\[endif\][^>]*?\>)?'. ')/is'; // Dot matches line breaks. @@ -895,7 +896,7 @@ protected function get_js_tag_frags(array $html_frag) $regex = '/(?P'. // Entire match. '(?P\<\![^[>]*?\[if\W[^\]]*?\][^>]*?\>\s*)?'. - '(?P\]*?)?\>)(?P.*?)(?P\<\/script\>)'. + '(?P\]*?)?\>)(?P.*?)(?P\<\/script\>)'. '(?P\s*\<\![^[>]*?\[endif\][^>]*?\>)?'. ')/is'; // Dot matches line breaks.