Skip to content
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

Improve performance by inlining constants #2636

Merged
merged 1 commit into from Mar 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/Twig/Extension/Core.php
Expand Up @@ -1432,10 +1432,10 @@ function twig_array_batch($items, $size, $fill = null)
*
* @internal
*/
function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false, $sandboxed = false)
function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, $item, array $arguments = array(), $type = /* Twig_Template::ANY_CALL */ 'any', $isDefinedTest = false, $ignoreStrictCheck = false, $sandboxed = false)
{
// array
if (Twig_Template::METHOD_CALL !== $type) {
if (/* Twig_Template::METHOD_CALL */ 'method' !== $type) {
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;

if ((is_array($object) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object)))
Expand All @@ -1448,7 +1448,7 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object,
return $object[$arrayItem];
}

if (Twig_Template::ARRAY_CALL === $type || !is_object($object)) {
if (/* Twig_Template::ARRAY_CALL */ 'array' === $type || !is_object($object)) {
if ($isDefinedTest) {
return false;
}
Expand All @@ -1467,7 +1467,7 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object,
} else {
$message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object)));
}
} elseif (Twig_Template::ARRAY_CALL === $type) {
} elseif (/* Twig_Template::ARRAY_CALL */ 'array' === $type) {
if (null === $object) {
$message = sprintf('Impossible to access a key ("%s") on a null variable.', $item);
} else {
Expand Down Expand Up @@ -1508,7 +1508,7 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object,
}

// object property
if (Twig_Template::METHOD_CALL !== $type) {
if (/* Twig_Template::METHOD_CALL */ 'method' !== $type) {
if (isset($object->$item) || array_key_exists((string) $item, $object)) {
if ($isDefinedTest) {
return true;
Expand Down