Skip to content

Commit 156c689

Browse files
Revert string concat optimizations - there is no real improvement
I've run performance tests for string concat vs. array join: https://gist.github.com/andrey-legayev/24ed101a34d4775bf1b6f9879581f51a No real performance improvement (which surprised me). But anyway - I'm rolling back string concatenation improvements, because it doesn't make any sense.
1 parent ca502c3 commit 156c689

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,9 @@ public function getChildHtml($alias = '', $useCache = true)
520520
$out = $layout->renderElement($childName, $useCache);
521521
}
522522
} else {
523-
$outParts = [];
524523
foreach ($layout->getChildNames($name) as $child) {
525-
$elementHtml = $layout->renderElement($child, $useCache);
526-
if (!empty($elementHtml)) {
527-
$outParts[] = $elementHtml;
528-
}
524+
$out .= $layout->renderElement($child, $useCache);
529525
}
530-
$out = join('', $outParts);
531526
}
532527

533528
return $out;
@@ -556,14 +551,9 @@ public function getChildChildHtml($alias, $childChildAlias = '', $useCache = tru
556551
$childChildName = $layout->getChildName($childName, $childChildAlias);
557552
$out = $layout->renderElement($childChildName, $useCache);
558553
} else {
559-
$outParts = [];
560554
foreach ($layout->getChildNames($childName) as $childChild) {
561-
$elementHtml = $layout->renderElement($childChild, $useCache);
562-
if (!empty($elementHtml)) {
563-
$outParts[] = $elementHtml;
564-
}
555+
$out .= $layout->renderElement($childChild, $useCache);
565556
}
566-
$out = join('', $outParts);
567557
}
568558
return $out;
569559
}

lib/internal/Magento/Framework/View/Layout.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -586,16 +586,13 @@ protected function _renderUiComponent($name)
586586
*/
587587
protected function _renderContainer($name, $useCache = true)
588588
{
589-
$htmlParts = [];
589+
$html = '';
590590
$children = $this->getChildNames($name);
591591
foreach ($children as $child) {
592-
$childHtml = $this->renderElement($child, $useCache);
593-
if (!empty($childHtml)) {
594-
$htmlParts[] = $childHtml;
595-
}
592+
$html .= $this->renderElement($child, $useCache);
596593
}
597-
if (empty($htmlParts) || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) {
598-
return join('', $htmlParts);
594+
if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) {
595+
return $html;
599596
}
600597

601598
$htmlId = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_ID);
@@ -609,7 +606,8 @@ protected function _renderContainer($name, $useCache = true)
609606
}
610607

611608
$htmlTag = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG);
612-
$html = sprintf('<%1$s%2$s%3$s>%4$s</%1$s>', $htmlTag, $htmlId, $htmlClass, join('', $htmlParts));
609+
610+
$html = sprintf('<%1$s%2$s%3$s>%4$s</%1$s>', $htmlTag, $htmlId, $htmlClass, $html);
613611

614612
return $html;
615613
}

0 commit comments

Comments
 (0)