Skip to content

Commit

Permalink
Only store and process structures that use braces
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Jan 12, 2015
1 parent d6e8a70 commit 7f3e6a4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Passes/OptimizeControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function optimize(TokenStream $stream)
{
if ($this->isControlStructure())
{
$structures[] = $this->parseControlStructure();
$structure = $this->parseControlStructure();
if ($structure)
{
$structures[] = $structure;
}
}
$this->stream->next();
}
Expand Down Expand Up @@ -95,11 +99,6 @@ protected function optimizeStructure(array $structure)
$this->optimizeStructures($structure['structures']);
}

if (!isset($structure['offsetRightBrace']))
{
return;
}

if ($structure['isIf'] || $structure['isElseif'])
{
$this->markPreservedBraces($structure['offsetRightBrace']);
Expand Down Expand Up @@ -132,7 +131,7 @@ protected function optimizeStructures(array $structures)
/**
* Parse the control structure starting at current offset
*
* @return array
* @return array|false
*/
protected function parseControlStructure()
{
Expand All @@ -159,7 +158,7 @@ protected function parseControlStructure()

if ($this->stream->current() !== '{')
{
return $structure;
return false;
}

$braces = 0;
Expand Down Expand Up @@ -190,7 +189,11 @@ protected function parseControlStructure()
++$structure['statements'];
}

$structure['structures'][] = $this->parseControlStructure();
$innerStructure = $this->parseControlStructure();
if ($innerStructure)
{
$structure['structures'][] = $innerStructure;
}
}

$this->stream->next();
Expand Down

0 comments on commit 7f3e6a4

Please sign in to comment.