Skip to content

Commit

Permalink
[DependencyInjection] made a small performance enhancement. No need t…
Browse files Browse the repository at this point in the history
…o lowercase three times the same.

`strtolower` was called three times at most on the same value, and one
at least. To avoid this, let's compute it first.

Additionally, $value cast in last return clause was useless as it has
been done previously, and nothing changed $value's value.

Signed-off-by: Romain Dorgueil <romain.dorgueil@symfony-project.com>
  • Loading branch information
Romain Dorgueil authored and fabpot committed Mar 1, 2010
1 parent 8948ae1 commit 3671f4a
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -65,23 +65,24 @@ public function getArgumentsAsPhp($name)
static public function phpize($value)
{
$value = (string) $value;
$lowercaseValue = strtolower($value);

switch (true)
{
case 'null' == strtolower($value):
case 'null' === $lowercaseValue:
return null;
case ctype_digit($value):
return '0' == $value[0] ? octdec($value) : intval($value);
case 'true' === strtolower($value):
case 'true' === $lowercaseValue:
return true;
case 'false' === strtolower($value):
case 'false' === $lowercaseValue:
return false;
case is_numeric($value):
return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value);
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value):
return floatval(str_replace(',', '', $value));
default:
return (string) $value;
return $value;
}
}
}

0 comments on commit 3671f4a

Please sign in to comment.