From d95aeed9354605abd1391ce5f78dff4c2796c62c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 16 Jul 2011 21:08:20 +0200 Subject: [PATCH] made a small optimization on Core functions --- lib/Twig/Extension/Core.php | 34 ++++++++++++---------------------- 1 files changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index a1cdf42..9211291 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -89,31 +89,12 @@ class Twig_Extension_Core extends Twig_Extension public function getFunctions() { return array( - 'range' => new Twig_Function_Method($this, 'getRange'), - 'constant' => new Twig_Function_Method($this, 'getConstant'), - 'cycle' => new Twig_Function_Method($this, 'getCycle'), + 'range' => new Twig_Function_Function('range'), + 'constant' => new Twig_Function_Function('constant'), + 'cycle' => new Twig_Function_Function('twig_cycle'), ); } - public function getRange($start, $end, $step = 1) - { - return range($start, $end, $step); - } - - public function getConstant($value) - { - return constant($value); - } - - public function getCycle($values, $i) - { - if (!is_array($values) && !$values instanceof ArrayAccess) { - return $values; - } - - return $values[$i % count($values)]; - } - /** * Returns a list of filters to add to the existing list. * @@ -201,6 +182,15 @@ class Twig_Extension_Core extends Twig_Extension } } +function twig_cycle($values, $i) +{ + if (!is_array($values) && !$values instanceof ArrayAccess) { + return $values; + } + + return $values[$i % count($values)]; +} + function twig_date_format_filter($date, $format = 'F j, Y H:i', $timezone = null) { if (!$date instanceof DateTime) { -- 1.7.2.5