Avoid needing two arrays

We only need to collect elements, we can discard finished blocks
This commit is contained in:
Aidan Woods 2018-04-08 20:29:09 +01:00
parent 39df7d4f8e
commit 5353ebb524
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -174,6 +174,7 @@ class Parsedown
protected function linesElements(array $lines) protected function linesElements(array $lines)
{ {
$Elements = array();
$CurrentBlock = null; $CurrentBlock = null;
foreach ($lines as $line) foreach ($lines as $line)
@ -278,7 +279,10 @@ class Parsedown
if ( ! isset($Block['identified'])) if ( ! isset($Block['identified']))
{ {
$Blocks []= $CurrentBlock; if (isset($CurrentBlock))
{
$Elements[] = $CurrentBlock['element'];
}
$Block['identified'] = true; $Block['identified'] = true;
} }
@ -306,7 +310,10 @@ class Parsedown
} }
else else
{ {
$Blocks []= $CurrentBlock; if (isset($CurrentBlock))
{
$Elements[] = $CurrentBlock['element'];
}
$CurrentBlock = $this->paragraph($Line); $CurrentBlock = $this->paragraph($Line);
@ -323,22 +330,9 @@ class Parsedown
# ~ # ~
$Blocks []= $CurrentBlock; if (isset($CurrentBlock))
unset($Blocks[0]);
# ~
$Elements = array();
foreach ($Blocks as $Block)
{ {
if (isset($Block['hidden'])) $Elements[] = $CurrentBlock['element'];
{
continue;
}
$Elements[] = $Block['element'];
} }
# ~ # ~