Skip to content

Commit f292516

Browse files
committed
Merge pull request #39 from DeuxHuitHuit/tab-perf
Performance improvement on tabs replacement
2 parents f78626c + b3aabb7 commit f292516

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)