Skip to content

Commit

Permalink
Don't iterate over positions that have already been unset
Browse files Browse the repository at this point in the history
Fixes #245
  • Loading branch information
matthiasmullie committed Apr 18, 2018
1 parent 2e54f84 commit ab7fea8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ protected function replace($content)
foreach ($this->patterns as $i => $pattern) {
list($pattern, $replacement) = $pattern;

// we can safely ignore patterns for positions we've unset earlier,
// because we know these won't show up anymore
if (!isset($positions[$i])) {
continue;
}

// no need to re-run matches that are still in the part of the
// content that hasn't been processed
if ($positions[$i] >= 0) {
Expand All @@ -257,8 +263,7 @@ protected function replace($content)
// if the pattern couldn't be matched, there's no point in
// executing it again in later runs on this same content;
// ignore this one until we reach end of content
unset($matches[$i]);
unset($positions[$i]);
unset($matches[$i], $positions[$i]);
}
}

Expand Down

0 comments on commit ab7fea8

Please sign in to comment.