Skip to content

Commit

Permalink
simplified logic and improve perf slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 13, 2015
1 parent 77c94ea commit 7030fdd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,5 +1,6 @@
* 1.22.3 (2015-XX-XX)

* improved performance when checking template freshness
* changed template cache names to take into account the Twig C extension

* 1.22.2 (2015-09-22)
Expand Down
14 changes: 4 additions & 10 deletions lib/Twig/Environment.php
Expand Up @@ -455,15 +455,6 @@ public function createTemplate($template)
*/
public function isTemplateFresh($name, $time)
{
if(0 === $this->lastModifiedExtension) {
foreach ($this->extensions as $extension) {
$r = new ReflectionObject($extension);
if (($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) {
$this->lastModifiedExtension = $extensionTime;
}
}
}

return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time);
}

Expand Down Expand Up @@ -770,7 +761,10 @@ public function addExtension(Twig_ExtensionInterface $extension)
throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName()));
}

$this->lastModifiedExtension = 0;
$r = new ReflectionObject($extension);
if (($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) {
$this->lastModifiedExtension = $extensionTime;
}

$this->extensions[$extension->getName()] = $extension;
}
Expand Down

0 comments on commit 7030fdd

Please sign in to comment.