Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Yaml] save preg_match() calls when possible #28106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2018

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Aug 1, 2018

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets possibly #27960
License MIT
Doc PR

@xabbuh
Copy link
Member Author

xabbuh commented Aug 1, 2018

This is how it looks like:

Parsing the services.yaml file from the FrameworkBundle recipe:

bildschirmfoto 2018-08-01 um 20 45 06

(see
https://blackfire.io/profiles/compare/b59c7350-088d-4a74-be43-45a39152ce89/graph)

Executing the Yaml component test suite:

bildschirmfoto 2018-08-01 um 20 49 28

(see https://blackfire.io/profiles/compare/b2f2e6a6-87d3-40ad-95dd-52a2ba6bdda7/graph)

@fabpot
Copy link
Member

fabpot commented Aug 2, 2018

Thank you @xabbuh.

@fabpot fabpot merged commit e6bea97 into symfony:master Aug 2, 2018
fabpot added a commit that referenced this pull request Aug 2, 2018
This PR was merged into the 4.2-dev branch.

Discussion
----------

[Yaml] save preg_match() calls when possible

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | possibly #27960
| License       | MIT
| Doc PR        |

Commits
-------

e6bea97 save preg_match() calls when possible
@staabm
Copy link
Contributor

staabm commented Aug 2, 2018

@xabbuh why does it save so much time in IOWait? The changes are not IO related..

@xabbuh xabbuh deleted the issue-27960 branch August 2, 2018 13:39
if ($context && 'mapping' == $context) {
throw new ParseException('You cannot define a sequence item when in a mapping', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
}
$context = 'sequence';

if (isset($values['value']) && self::preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {
if (isset($values['value']) && '&' === $values['value'][0] && self::preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have $values['value'] being the empty string here or no ? If yes, we have a bug.

Copy link
Member Author

@xabbuh xabbuh Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the regular expression that has to match to reach this part of the code is #^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u. So if the value element is set, it must have at least on character.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the value group can indeed not be empty when it is matched, so things are fine.

@@ -1009,7 +1011,7 @@ private function isStringUnIndentedCollectionItem(): bool
*/
private function isBlockScalarHeader(): bool
{
return (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
return '' !== $this->currentLine && (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding && \in_array($this->currentLine[0], array('|', '>'), true) && here too ?

Copy link
Member Author

@xabbuh xabbuh Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that too, but the regular expression should also match lines like foo: | or foo: >2, shouldn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm indeed. This regex is not anchored at the start. I missed that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just remembered that I indeed tried to add that check and was wondering now why tests didn't fail then. Turns out this method is totally useless with the current code (see #28187).

@stof
Copy link
Member

stof commented Aug 2, 2018

@staabm probably cold vs warm OPCache cache (and so bypassing the IO for many files)

@xabbuh
Copy link
Member Author

xabbuh commented Aug 2, 2018

@staabm I think what @stof said. You can see updated profile comparisons at https://blackfire.io/profiles/compare/9de46b73-d563-4e0e-a81a-553cc3d5f290/graph (parsing the services.yaml file) and https://blackfire.io/profiles/compare/6effa0a7-6309-465e-a9a5-fb1863b96813/graph (running the Yaml component test suite).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants