minor #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
This commit is contained in:
commit
3188b0e49c
@ -400,7 +400,7 @@ class Parser
|
||||
$blockScalarIndentations = array();
|
||||
|
||||
if ($this->isBlockScalarHeader()) {
|
||||
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
|
||||
$blockScalarIndentations[] = $oldLineIndentation;
|
||||
}
|
||||
|
||||
if (!$this->moveToNextLine()) {
|
||||
@ -450,14 +450,14 @@ class Parser
|
||||
// terminate all block scalars that are more indented than the current line
|
||||
if (!empty($blockScalarIndentations) && $indent < $previousLineIndentation && trim($this->currentLine) !== '') {
|
||||
foreach ($blockScalarIndentations as $key => $blockScalarIndentation) {
|
||||
if ($blockScalarIndentation >= $this->getCurrentLineIndentation()) {
|
||||
if ($blockScalarIndentation >= $indent) {
|
||||
unset($blockScalarIndentations[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($blockScalarIndentations) && !$this->isCurrentLineComment() && $this->isBlockScalarHeader()) {
|
||||
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
|
||||
$blockScalarIndentations[] = $indent;
|
||||
}
|
||||
|
||||
$previousLineIndentation = $indent;
|
||||
|
Reference in New Issue
Block a user