8000 [Yaml] execute cheaper checks before more expensive ones by xabbuh · Pull Request #13430 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] execute cheaper checks before more expensive ones #13430

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
Jan 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Symfony/Component/Yaml/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public static function escapeWithDoubleQuotes($value)
*/
public static function requiresSingleQuoting($value)
{
// Determines if the PHP value contains any single characters that would
// cause it to require single quoting in YAML.
if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) {
// Determines if a PHP value is entirely composed of a value that would
// require single quoting in YAML.
if (in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) {
return true;
}

// Determines if a PHP value is entirely composed of a value that would
// require single quoting in YAML.
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
// Determines if the PHP value contains any single characters that would
// cause it to require single quoting in YAML.
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
}

return $repr;
case '' == $value:
return "''";
case Escaper::requiresDoubleQuoting($value):
return Escaper::escapeWithDoubleQuotes($value);
case Escaper::requiresSingleQuoting($value):
case preg_match(self::getTimestampRegex(), $value):
return Escaper::escapeWithSingleQuotes($value);
case '' == $value:
return "''";
default:
return $value;
}
Expand Down
0