Skip to content

Commit 3188b0e

Browse files
committed
minor symfony#20818 [Yaml] Small optimization of the parser (GuilhemN)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Yaml] Small optimization of the parser | Q | A | ------------- | --- | Branch? | "master" | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Very small optimization in the Yaml parser but as it is executed often, there are performance gains (I used [this benchmark](https://gist.github.com/GuilhemN/364c4ddcc8349eaa080054d5f8ef8685); you can see the [comparison master / this PR](https://blackfire.io/profiles/compare/0f4e5497-d410-4c76-83e9-d8fa8e46ce18/graph)). Commits ------- 5fc8e86 [Yaml] Small optimization of the parser
2 parents 4033b60 + 5fc8e86 commit 3188b0e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
400400
$blockScalarIndentations = array();
401401

402402
if ($this->isBlockScalarHeader()) {
403-
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
403+
$blockScalarIndentations[] = $oldLineIndentation;
404404
}
405405

406406
if (!$this->moveToNextLine()) {
@@ -450,14 +450,14 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
450450
// terminate all block scalars that are more indented than the current line
451451
if (!empty($blockScalarIndentations) && $indent < $previousLineIndentation && trim($this->currentLine) !== '') {
452452
foreach ($blockScalarIndentations as $key => $blockScalarIndentation) {
453-
if ($blockScalarIndentation >= $this->getCurrentLineIndentation()) {
453+
if ($blockScalarIndentation >= $indent) {
454454
unset($blockScalarIndentations[$key]);
455455
}
456456
}
457457
}
458458

459459
if (empty($blockScalarIndentations) && !$this->isCurrentLineComment() && $this->isBlockScalarHeader()) {
460-
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
460+
$blockScalarIndentations[] = $indent;
461461
}
462462

463463
$previousLineIndentation = $indent;

0 commit comments

Comments
 (0)