mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
made some small optimizations
This commit is contained in:
+19
-5
@@ -52,23 +52,29 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
/**
|
||||
* Compiles a node.
|
||||
*
|
||||
* @param Twig_NodeInterface $node The node to compile
|
||||
* @param Twig_NodeInterface $node The node to compile
|
||||
* @param integer $indent The current indentation
|
||||
*
|
||||
* @return Twig_Compiler The current compiler instance
|
||||
*/
|
||||
public function compile(Twig_NodeInterface $node)
|
||||
public function compile(Twig_NodeInterface $node, $indentation = 0)
|
||||
{
|
||||
$this->lastLine = null;
|
||||
$this->source = '';
|
||||
$this->indentation = 0;
|
||||
$this->indentation = $indentation;
|
||||
|
||||
$node->compile($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function subcompile(Twig_NodeInterface $node)
|
||||
public function subcompile(Twig_NodeInterface $node, $raw = true)
|
||||
{
|
||||
if (false === $raw)
|
||||
{
|
||||
$this->addIndentation();
|
||||
}
|
||||
|
||||
$node->compile($this);
|
||||
|
||||
return $this;
|
||||
@@ -97,12 +103,20 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
{
|
||||
$strings = func_get_args();
|
||||
foreach ($strings as $string) {
|
||||
$this->source .= str_repeat(' ', $this->indentation * 4).$string;
|
||||
$this->addIndentation();
|
||||
$this->source .= $string;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addIndentation()
|
||||
{
|
||||
$this->source .= str_repeat(' ', $this->indentation * 4);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a quoted string to the compiled code.
|
||||
*
|
||||
|
||||
@@ -31,12 +31,15 @@ abstract class Twig_Node_Expression_Unary extends Twig_Node_Expression
|
||||
|
||||
return implode("\n", $repr);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->raw('(');
|
||||
$this->operator($compiler);
|
||||
$this->node->compile($compiler);
|
||||
$compiler->raw(')');
|
||||
$compiler
|
||||
->subcompile($this->node)
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
abstract public function operator($compiler);
|
||||
|
||||
+2
-10
@@ -71,11 +71,7 @@ class Twig_Node_Set extends Twig_Node implements Twig_NodeListInterface
|
||||
$compiler->raw(', ');
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('$context[')
|
||||
->string($node->getName())
|
||||
->raw(']')
|
||||
;
|
||||
$compiler->subcompile($node);
|
||||
}
|
||||
$compiler->raw(')');
|
||||
} else {
|
||||
@@ -86,11 +82,7 @@ class Twig_Node_Set extends Twig_Node implements Twig_NodeListInterface
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->write('$context[')
|
||||
->string($this->names->getName())
|
||||
->raw(']')
|
||||
;
|
||||
$compiler->subcompile($this->names, false);
|
||||
|
||||
if ($this->capture) {
|
||||
$compiler->raw(" = ob_get_clean()");
|
||||
|
||||
Reference in New Issue
Block a user