Skip to content

Commit

Permalink
Merge pull request #84 from scrivo/hotfix/regex-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo authored Nov 22, 2020
2 parents ee8007a + c013424 commit fa75a86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
fail-fast: false
matrix:
php-versions:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
Expand Down
7 changes: 4 additions & 3 deletions Highlight/RegEx.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public function exec($str)
{
$index = null;
$results = array();
preg_match_all($this->source, $str, $results, PREG_SET_ORDER | PREG_OFFSET_CAPTURE, $this->lastIndex);
preg_match($this->source, $str, $results, PREG_OFFSET_CAPTURE, $this->lastIndex);

if ($results === null || count($results) === 0) {
return null;
}

foreach ($results[0] as &$result) {
foreach ($results as &$result) {
if ($result[1] !== -1) {
// Only save the index if it hasn't been set yet
if ($index === null) {
Expand All @@ -95,7 +95,8 @@ public function exec($str)
}
}

$results = $results[0];
unset($result);

$this->lastIndex += mb_strlen($results[0]) + ($index - $this->lastIndex);

$matches = new RegExMatch($results);
Expand Down

0 comments on commit fa75a86

Please sign in to comment.