merged branch dlsniper/php-engine-escape-cache (PR #5117)
Commits -------22cb817
Caching variables for the PHP templating engine Discussion ---------- [Templating] PHP templating engine speed-ups Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/dlsniper/symfony.png?branch=php-engine-escape-cache)](http://travis-ci.org/dlsniper/symfony) Fixes the following tickets: ~ Todo: ~ License of the code: MIT Documentation PR: ~ This PR should improve the speed for rendering the form present here: https://github.com/dlsniper/symfony-standard . On my computer, Ubuntu 12.04 Apache 2.2.22 + mod_php 5.3.10 default packages from Ubuntu on a core i7 I get about 30-40ms improvement / request with the first commit and with the second one I get a further smaller boost and also a small memory usage decrease. --------------------------------------------------------------------------- by dlsniper at 2012-07-31T06:18:54Z ping @bschussek This should help a bit more on the effort for optimizing the example provided for the Forms component. If there's another example of complex form(s) let me know so that I can have a look on them as well. Thanks! --------------------------------------------------------------------------- by travisbot at 2012-07-31T19:55:03Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/2003907) (merged 240152b9 intoa172a812
). --------------------------------------------------------------------------- by dlsniper at 2012-08-02T07:41:03Z @fabpot what do you think about this? or anyone else for that matter? --------------------------------------------------------------------------- by travisbot at 2012-08-02T12:55:54Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/2018613) (merged 5e773e79 intoa172a812
). --------------------------------------------------------------------------- by fabpot at 2012-08-03T07:42:31Z Can you squash your commits? --------------------------------------------------------------------------- by dlsniper at 2012-08-03T08:32:05Z @fabpot Done --------------------------------------------------------------------------- by travisbot at 2012-08-03T08:40:46Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/2026559) (merged22cb8173
into6f32078b
).
This commit is contained in:
commit
6b94407e1c
@ -38,7 +38,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
protected $charset;
|
||||
protected $cache;
|
||||
protected $escapers;
|
||||
protected $escaperCache;
|
||||
protected static $escaperCache;
|
||||
protected $globals;
|
||||
protected $parser;
|
||||
|
||||
@ -335,14 +335,18 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
*/
|
||||
public function escape($value, $context = 'html')
|
||||
{
|
||||
if (is_numeric($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// If we deal with a scalar value, we can cache the result to increase
|
||||
// the performance when the same value is escaped multiple times (e.g. loops)
|
||||
if (is_scalar($value)) {
|
||||
if (!isset($this->escaperCache[$context][$value])) {
|
||||
$this->escaperCache[$context][$value] = call_user_func($this->getEscaper($context), $value);
|
||||
if (!isset(self::$escaperCache[$context][$value])) {
|
||||
self::$escaperCache[$context][$value] = call_user_func($this->getEscaper($context), $value);
|
||||
}
|
||||
|
||||
return $this->escaperCache[$context][$value];
|
||||
return self::$escaperCache[$context][$value];
|
||||
}
|
||||
|
||||
return call_user_func($this->getEscaper($context), $value);
|
||||
@ -383,7 +387,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
public function setEscaper($context, $escaper)
|
||||
{
|
||||
$this->escapers[$context] = $escaper;
|
||||
$this->escaperCache[$context] = array();
|
||||
self::$escaperCache[$context] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,7 +506,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
||||
},
|
||||
);
|
||||
|
||||
$this->escaperCache = array();
|
||||
self::$escaperCache = array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user