Skip to content

Commit b3aabb7

Browse files
committed
Performance improvement on tabs replacement: process the regex line by line instead of for the hole output
1 parent f78626c commit b3aabb7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

lib/bitter/formats/symphony.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ public function process($source) {
1919
}
2020

2121
protected function processTabs() {
22-
while (strstr($this->output, "\t")) {
23-
$this->output = preg_replace_callback('%^([^\t]*)(\t+)%', array($this, 'processTabsLine'), $this->output);
22+
// first split the output into manageable chunks
23+
$lines = explode(PHP_EOL, $this->output);
24+
$linesCount = count($lines);
25+
// fix lines one by one
26+
for ($x = 0; $x < $linesCount; $x++) {
27+
// while there are still tabs
28+
while (strpos($lines[$x], "\t") !== FALSE) {
29+
// replace tabs for spaces
30+
$lines[$x] = preg_replace_callback('%^([^\t]*)([\t]+)%', array($this, 'processTabsLine'), $lines[$x]);
31+
}
2432
}
33+
// concat the final output
34+
$this->output = implode(PHP_EOL, $lines);
2535
}
2636

2737
protected function processTabsLine($matches) {

0 commit comments

Comments
 (0)