1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

String interpolation is slightly faster than concat

This commit is contained in:
Aidan Woods 2018-04-08 21:24:45 +01:00
parent d6e306d620
commit d4f1ac465c
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -216,7 +216,7 @@ class Parsedown
if (isset($CurrentBlock['continuable'])) if (isset($CurrentBlock['continuable']))
{ {
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock); $Block = $this->{"block{$CurrentBlock['type']}Continue"}($Line, $CurrentBlock);
if (isset($Block)) if (isset($Block))
{ {
@ -228,7 +228,7 @@ class Parsedown
{ {
if ($this->isBlockCompletable($CurrentBlock['type'])) if ($this->isBlockCompletable($CurrentBlock['type']))
{ {
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); $CurrentBlock = $this->{"block{$CurrentBlock['type']}Complete"}($CurrentBlock);
} }
} }
} }
@ -254,7 +254,7 @@ class Parsedown
foreach ($blockTypes as $blockType) foreach ($blockTypes as $blockType)
{ {
$Block = $this->{'block'.$blockType}($Line, $CurrentBlock); $Block = $this->{"block$blockType"}($Line, $CurrentBlock);
if (isset($Block)) if (isset($Block))
{ {
@ -309,7 +309,7 @@ class Parsedown
if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type'])) if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
{ {
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); $CurrentBlock = $this->{"block{$CurrentBlock['type']}Complete"}($CurrentBlock);
} }
# ~ # ~
@ -326,12 +326,12 @@ class Parsedown
protected function isBlockContinuable($Type) protected function isBlockContinuable($Type)
{ {
return method_exists($this, 'block'.$Type.'Continue'); return method_exists($this, "block${Type}Continue");
} }
protected function isBlockCompletable($Type) protected function isBlockCompletable($Type)
{ {
return method_exists($this, 'block'.$Type.'Complete'); return method_exists($this, "block${Type}Complete");
} }
# #
@ -427,7 +427,7 @@ class Parsedown
return; return;
} }
$Block['element']['rawHtml'] .= "\n" . $Line['body']; $Block['element']['rawHtml'] .= "\n{$Line['body']}";
if (strpos($Line['text'], '-->') !== false) if (strpos($Line['text'], '-->') !== false)
{ {
@ -451,7 +451,7 @@ class Parsedown
if (isset($matches[2])) if (isset($matches[2]))
{ {
$class = 'language-'.$matches[2]; $class = "language-{$matches[2]}";
$Element['attributes'] = array( $Element['attributes'] = array(
'class' => $class, 'class' => $class,
@ -496,7 +496,7 @@ class Parsedown
return $Block; return $Block;
} }
$Block['element']['element']['text'] .= "\n".$Line['body']; $Block['element']['element']['text'] .= "\n{$Line['body']}";
return $Block; return $Block;
} }
@ -840,7 +840,7 @@ class Parsedown
return; return;
} }
$Block['element']['rawHtml'] .= "\n".$Line['body']; $Block['element']['rawHtml'] .= "\n{$Line['body']}";
return $Block; return $Block;
} }
@ -960,7 +960,7 @@ class Parsedown
$alignment = $alignments[$index]; $alignment = $alignments[$index];
$HeaderElement['attributes'] = array( $HeaderElement['attributes'] = array(
'style' => 'text-align: '.$alignment.';', 'style' => "text-align: $alignment;",
); );
} }
@ -1031,7 +1031,7 @@ class Parsedown
if (isset($Block['alignments'][$index])) if (isset($Block['alignments'][$index]))
{ {
$Element['attributes'] = array( $Element['attributes'] = array(
'style' => 'text-align: '.$Block['alignments'][$index].';', 'style' => "text-align: {$Block['alignments'][$index]};",
); );
} }
@ -1135,7 +1135,7 @@ class Parsedown
continue; continue;
} }
$Inline = $this->{'inline'.$inlineType}($Excerpt); $Inline = $this->{"inline$inlineType"}($Excerpt);
if ( ! isset($Inline)) if ( ! isset($Inline))
{ {
@ -1263,7 +1263,7 @@ class Parsedown
if ( ! isset($matches[2])) if ( ! isset($matches[2]))
{ {
$url = 'mailto:' . $url; $url = "mailto:$url";
} }
return array( return array(
@ -1472,7 +1472,7 @@ class Parsedown
if (preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches)) if (preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches))
{ {
return array( return array(
'element' => array('rawHtml' => '&'.$matches[1].';'), 'element' => array('rawHtml' => "&{$matches[1]};"),
'extent' => strlen($matches[0]), 'extent' => strlen($matches[0]),
); );
} }
@ -1674,7 +1674,7 @@ class Parsedown
if ($hasName) if ($hasName)
{ {
$markup .= '<'.$Element['name']; $markup .= "<{$Element['name']}";
if (isset($Element['attributes'])) if (isset($Element['attributes']))
{ {
@ -1685,7 +1685,7 @@ class Parsedown
continue; continue;
} }
$markup .= ' '.$name.'="'.self::escape($value).'"'; $markup .= " $name=\"".self::escape($value).'"';
} }
} }
} }
@ -1732,7 +1732,7 @@ class Parsedown
} }
} }
$markup .= $hasName ? '</'.$Element['name'].'>' : ''; $markup .= $hasName ? "</{$Element['name']}>" : '';
} }
elseif ($hasName) elseif ($hasName)
{ {