mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- minor compiler optimizations
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
- update Smarty security with new realpath handling
|
- update Smarty security with new realpath handling
|
||||||
- update {include_php} with new realpath handling
|
- update {include_php} with new realpath handling
|
||||||
- move $smarty->loadPlugin() into extension
|
- move $smarty->loadPlugin() into extension
|
||||||
|
- minor compiler optimizations
|
||||||
|
|
||||||
19.06.2015
|
19.06.2015
|
||||||
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
|
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
|
||||||
|
@@ -106,7 +106,7 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
|
|||||||
$this->lex->PrintTrace();
|
$this->lex->PrintTrace();
|
||||||
}
|
}
|
||||||
// get tokens from lexer and parse them
|
// get tokens from lexer and parse them
|
||||||
while ($this->lex->yylex() && !$this->abort_and_recompile) {
|
while ($this->lex->yylex()) {
|
||||||
if ($this->smarty->_parserdebug) {
|
if ($this->smarty->_parserdebug) {
|
||||||
echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
|
echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
|
||||||
htmlentities($this->lex->value) . "</pre>";
|
htmlentities($this->lex->value) . "</pre>";
|
||||||
@@ -114,10 +114,6 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
|
|||||||
$this->parser->doParse($this->lex->token, $this->lex->value);
|
$this->parser->doParse($this->lex->token, $this->lex->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->abort_and_recompile) {
|
|
||||||
// exit here on abort
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// finish parsing process
|
// finish parsing process
|
||||||
$this->parser->doParse(0, 0);
|
$this->parser->doParse(0, 0);
|
||||||
if ($mbEncoding) {
|
if ($mbEncoding) {
|
||||||
|
@@ -825,7 +825,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function loadCompiler()
|
public function loadCompiler()
|
||||||
{
|
{
|
||||||
|
if (!class_exists($this->source->compiler_class)) {
|
||||||
$this->smarty->loadPlugin($this->source->compiler_class);
|
$this->smarty->loadPlugin($this->source->compiler_class);
|
||||||
|
}
|
||||||
$this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
|
$this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -249,13 +249,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
*/
|
*/
|
||||||
public $tag_nocache = false;
|
public $tag_nocache = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag to restart parsing
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $abort_and_recompile = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiled tag prefix code
|
* Compiled tag prefix code
|
||||||
*
|
*
|
||||||
@@ -362,14 +355,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
Smarty_Internal_Debug::start_compile($this->template);
|
Smarty_Internal_Debug::start_compile($this->template);
|
||||||
}
|
}
|
||||||
$no_sources = count($this->sources);
|
$no_sources = count($this->sources);
|
||||||
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
|
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath,
|
||||||
|
$this->template->source->timestamp, $this->template->source->type);
|
||||||
$loop ++;
|
$loop ++;
|
||||||
if ($no_sources) {
|
if ($no_sources) {
|
||||||
$this->inheritance_child = true;
|
$this->inheritance_child = true;
|
||||||
} else {
|
} else {
|
||||||
$this->inheritance_child = false;
|
$this->inheritance_child = false;
|
||||||
}
|
}
|
||||||
do {
|
|
||||||
// flag for nochache sections
|
// flag for nochache sections
|
||||||
$this->nocache = $nocache;
|
$this->nocache = $nocache;
|
||||||
$this->tag_nocache = false;
|
$this->tag_nocache = false;
|
||||||
@@ -378,8 +371,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$this->has_variable_string = false;
|
$this->has_variable_string = false;
|
||||||
$this->prefix_code = array();
|
$this->prefix_code = array();
|
||||||
$_compiled_code = '';
|
$_compiled_code = '';
|
||||||
// flag for aborting current and start recompile
|
|
||||||
$this->abort_and_recompile = false;
|
|
||||||
// get template source
|
// get template source
|
||||||
$_content = $this->template->source->content;
|
$_content = $this->template->source->content;
|
||||||
if ($_content != '') {
|
if ($_content != '') {
|
||||||
@@ -390,7 +381,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
// call compiler
|
// call compiler
|
||||||
$_compiled_code = $this->doCompile($_content, true);
|
$_compiled_code = $this->doCompile($_content, true);
|
||||||
}
|
}
|
||||||
} while ($this->abort_and_recompile);
|
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::end_compile($this->template);
|
Smarty_Internal_Debug::end_compile($this->template);
|
||||||
}
|
}
|
||||||
@@ -401,7 +391,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$this->smarty->_current_file = $this->template->source->filepath;
|
$this->smarty->_current_file = $this->template->source->filepath;
|
||||||
// free memory
|
// free memory
|
||||||
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex);
|
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex);
|
||||||
self::$_tag_objects = array();
|
|
||||||
// return compiled code to template object
|
// return compiled code to template object
|
||||||
$merged_code = '';
|
$merged_code = '';
|
||||||
if (!empty($this->mergedSubTemplatesCode)) {
|
if (!empty($this->mergedSubTemplatesCode)) {
|
||||||
@@ -482,8 +471,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$this->template->used_tags[] = array($tag, $args);
|
$this->template->used_tags[] = array($tag, $args);
|
||||||
}
|
}
|
||||||
// check nocache option flag
|
// check nocache option flag
|
||||||
if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)
|
if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)) {
|
||||||
) {
|
|
||||||
$this->tag_nocache = true;
|
$this->tag_nocache = true;
|
||||||
}
|
}
|
||||||
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
|
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
|
||||||
@@ -522,8 +510,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
// check if tag is a registered object
|
// check if tag is a registered object
|
||||||
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) {
|
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) {
|
||||||
$method = $parameter['object_method'];
|
$method = $parameter['object_method'];
|
||||||
if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && (empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1]))
|
if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && (empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1]))) {
|
||||||
) {
|
|
||||||
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
|
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
|
||||||
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
|
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
|
||||||
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
|
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
|
||||||
@@ -533,7 +520,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if tag is registered
|
// check if tag is registered
|
||||||
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) {
|
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION,
|
||||||
|
Smarty::PLUGIN_BLOCK) as $plugin_type) {
|
||||||
if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) {
|
if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) {
|
||||||
// if compiler function plugin call it now
|
// if compiler function plugin call it now
|
||||||
if ($plugin_type == Smarty::PLUGIN_COMPILER) {
|
if ($plugin_type == Smarty::PLUGIN_COMPILER) {
|
||||||
@@ -831,7 +819,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$callback = null;
|
$callback = null;
|
||||||
$script = null;
|
$script = null;
|
||||||
$cacheable = true;
|
$cacheable = true;
|
||||||
$result = call_user_func_array($this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable));
|
$result = call_user_func_array($this->smarty->default_plugin_handler_func, array($tag, $plugin_type,
|
||||||
|
$this->template, &$callback, &$script, &$cacheable));
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->tag_nocache = $this->tag_nocache || !$cacheable;
|
$this->tag_nocache = $this->tag_nocache || !$cacheable;
|
||||||
if ($script !== null) {
|
if ($script !== null) {
|
||||||
@@ -898,8 +887,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
// If the template is not evaluated and we have a nocache section and or a nocache tag
|
// If the template is not evaluated and we have a nocache section and or a nocache tag
|
||||||
if ($is_code && !empty($content)) {
|
if ($is_code && !empty($content)) {
|
||||||
// generate replacement code
|
// generate replacement code
|
||||||
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
|
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)) {
|
||||||
) {
|
|
||||||
$this->template->has_nocache_code = true;
|
$this->template->has_nocache_code = true;
|
||||||
$_output = addcslashes($content, '\'\\');
|
$_output = addcslashes($content, '\'\\');
|
||||||
$_output = str_replace("^#^", "'", $_output);
|
$_output = str_replace("^#^", "'", $_output);
|
||||||
@@ -948,7 +936,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
if ($this->smarty->debugging && $debug) {
|
if ($this->smarty->debugging && $debug) {
|
||||||
Smarty_Internal_Debug::end_compile($this->template);
|
Smarty_Internal_Debug::end_compile($this->template);
|
||||||
}
|
}
|
||||||
array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, $this->trace_line_offset));
|
array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid,
|
||||||
|
$this->trace_line_offset));
|
||||||
$this->trace_filepath = $this->smarty->_current_file = $file;
|
$this->trace_filepath = $this->smarty->_current_file = $file;
|
||||||
$this->trace_uid = $uid;
|
$this->trace_uid = $uid;
|
||||||
$this->trace_line_offset = $line;
|
$this->trace_line_offset = $line;
|
||||||
|
Reference in New Issue
Block a user