minor #10323 [Yaml] Fixed minor performance related issues in Yaml\Inline. (sun)

This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #10323).

Discussion
----------

[Yaml] Fixed minor performance related issues in Yaml\Inline.

Follow-up to #10312

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

Commits
-------

a36fef5 Follow-up to #10312: Fixed minor performance related issues in Yaml\Inline.
This commit is contained in:
Fabien Potencier 2014-02-25 22:36:55 +01:00
commit ca60916331
1 changed files with 9 additions and 7 deletions

View File

@ -220,7 +220,9 @@ class Inline
throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar));
}
$output = $evaluate ? self::evaluateScalar($output) : $output;
if ($evaluate) {
$output = self::evaluateScalar($output);
}
}
return $output;
@ -388,9 +390,9 @@ class Inline
$scalar = trim($scalar);
$scalarLower = strtolower($scalar);
switch (true) {
case 'null' == $scalarLower:
case '' == $scalar:
case '~' == $scalar:
case 'null' === $scalarLower:
case '' === $scalar:
case '~' === $scalar:
return null;
case 'true' === $scalarLower:
return true;
@ -425,10 +427,10 @@ class Inline
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
case is_numeric($scalar):
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
case 0 == strcasecmp($scalar, '.inf'):
case 0 == strcasecmp($scalar, '.NaN'):
case '.inf' === $scalarLower:
case '.nan' === $scalarLower:
return -log(0);
case 0 == strcasecmp($scalar, '-.inf'):
case '-.inf' === $scalarLower:
return log(0);
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
return floatval(str_replace(',', '', $scalar));