Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c4c207

Browse files
committed
Fix atrocious performance in RegEx class
Forward port e98ea8f Fixes #78
1 parent e30a8d4 commit 7c4c207

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/Highlight/RegEx.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public function exec($str)
7676
{
7777
$index = null;
7878
$results = array();
79-
preg_match_all($this->source, $str, $results, PREG_SET_ORDER | PREG_OFFSET_CAPTURE, $this->lastIndex);
79+
preg_match($this->source, $str, $results, PREG_OFFSET_CAPTURE, $this->lastIndex);
8080

8181
if ($results === null || count($results) === 0) {
8282
return null;
8383
}
8484

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

98-
$results = $results[0];
98+
unset($result);
99+
99100
$this->lastIndex += mb_strlen($results[0]) + ($index - $this->lastIndex);
100101

101102
$matches = new RegExMatch($results);

0 commit comments

Comments
 (0)