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
1 changed files with 11 additions and 17 deletions

View File

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