8000 execute cheaper checks before more expensive ones · symfony/symfony@cd4349d · GitHub
[go: up one dir, main page]

Skip to content

Commit cd4349d

Browse files
committed
execute cheaper checks before more expensive ones
1 parent 689cf99 commit cd4349d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Symfony/Component/Yaml/Escaper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public static function escapeWithDoubleQuotes($value)
7272
*/
7373
public static function requiresSingleQuoting($value)
7474
{
75-
// Determines if the PHP value contains any single characters that would
76-
// cause it to require single quoting in YAML.
77-
if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) {
75+
// Determines if a PHP value is entirely composed of a value that would
76+
// require single quoting in YAML.
77+
if (in_a 10000 rray(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) {
7878
return true;
7979
}
8080

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

8686
/**

src/Symfony/Component/Yaml/Inline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
132132
}
133133

134134
return $repr;
135+
case '' == $value:
136+
return "''";
135137
case Escaper::requiresDoubleQuoting($value):
136138
return Escaper::escapeWithDoubleQuotes($value);
137139
case Escaper::requiresSingleQuoting($value):
138140
case preg_match(self::getTimestampRegex(), $value):
139141
return Escaper::escapeWithSingleQuotes($value);
140-
case '' == $value:
141-
return "''";
142142
default:
143143
return $value;
144144
}

0 commit comments

Comments
 (0)
0