- optimize {block} compilation

This commit is contained in:
Uwe Tews
2015-07-06 03:12:25 +02:00
parent 7e7112153a
commit b198e6488c
3 changed files with 22 additions and 25 deletions

View File

@@ -1,8 +1,12 @@
 ===== 3.1.28-dev===== (xx.xx.2015)  ===== 3.1.28-dev===== (xx.xx.2015)
06.07.2015
- optimize {block} compilation
01.07.2015 01.07.2015
- optimize compile check handling - optimize compile check handling
- update {foreach} compiler - update {foreach} compiler
- bugfix debugging console did not display string values containing \n, \r or \t correctly https://github.com/smarty-php/smarty/issues/66 - bugfix debugging console did not display string values containing \n, \r or \t correctly https://github.com/smarty-php/smarty/issues/66
- optimize source resources
28.06.2015 28.06.2015
- move $smarty->enableSecurity() into Smarty_Security class - move $smarty->enableSecurity() into Smarty_Security class

View File

@@ -44,14 +44,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
*/ */
public $option_flags = array('hide', 'append', 'prepend', 'nocache'); public $option_flags = array('hide', 'append', 'prepend', 'nocache');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('internal_file', 'internal_uid', 'internal_line');
/** /**
* nested child block names * nested child block names
* *
@@ -90,11 +82,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
if ($compiler->inheritance_child) { if ($compiler->inheritance_child) {
array_unshift(self::$nested_block_names, $_name); array_unshift(self::$nested_block_names, $_name);
// build {block} for child block // build {block} for child block
self::$block_data[$_name]['source'] = "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}' type='{$compiler->template->source->type}' resource='{$compiler->template->template_resource}'" . " uid='{$compiler->template->source->uid}' line={$compiler->lex->line}"; self::$block_data[$_name]['source'] = "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} uid='{$compiler->template->source->uid}' line={$compiler->lex->line}";
if ($_attr['nocache']) { if ($_attr['nocache']) {
self::$block_data[$_name]['source'] .= ' nocache'; self::$block_data[$_name]['source'] .= ' nocache';
} }
self::$block_data[$_name]['source'] .= $compiler->smarty->right_delimiter; self::$block_data[$_name]['source'] .= $compiler->smarty->right_delimiter;
// save source object
$compiler->cache["source_{$compiler->template->source->uid}"] = $compiler->template->source;
$save = array($_attr, $compiler->inheritance); $save = array($_attr, $compiler->inheritance);
$this->openTag($compiler, 'block', $save); $this->openTag($compiler, 'block', $save);
@@ -186,6 +180,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler); $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
} }
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']); $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
unset($compiler->template->properties['file_dependency'][$_tpl->source->uid]);
$compiler->template->properties['tpl_function'] = array_merge($compiler->template->properties['tpl_function'], $_tpl->properties['tpl_function']); $compiler->template->properties['tpl_function'] = array_merge($compiler->template->properties['tpl_function'], $_tpl->properties['tpl_function']);
$compiler->template->variable_filters = $_tpl->variable_filters; $compiler->template->variable_filters = $_tpl->variable_filters;
if ($_tpl->has_nocache_code) { if ($_tpl->has_nocache_code) {
@@ -368,7 +363,7 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name', 'file', 'uid', 'line', 'type', 'resource'); public $required_attributes = array('name', 'uid', 'line');
/** /**
* Compiles code for the {private_child_block} tag * Compiles code for the {private_child_block} tag
@@ -382,16 +377,9 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$uid = trim($_attr['uid'], "\"'");
// update template with original template resource of {block} // update template with original template source of {block}
if (trim($_attr['type'], "'") == 'file') { $compiler->template->source = $compiler->parent_compiler->cache["source_{$uid}"];
$compiler->template->template_resource = 'file:' . $compiler->template->smarty->_realpath(trim($_attr['file'], "'"));
} else {
$compiler->template->template_resource = trim($_attr['resource'], "'");
}
// source object
unset ($compiler->template->source);
$compiler->template->loadSource();
// must merge includes // must merge includes
if ($_attr['nocache'] == true) { if ($_attr['nocache'] == true) {
@@ -400,7 +388,7 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
$save = array($_attr, $compiler->nocache); $save = array($_attr, $compiler->nocache);
// set trace back to child block // set trace back to child block
$compiler->pushTrace(trim($_attr['file'], "\"'"), trim($_attr['uid'], "\"'"), $_attr['line'] - $compiler->lex->line); $compiler->pushTrace(trim($_attr['file'], "\"'"), $uid, $_attr['line'] - $compiler->lex->line);
$this->openTag($compiler, 'private_child_block', $save); $this->openTag($compiler, 'private_child_block', $save);

View File

@@ -297,6 +297,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public $has_output = false; public $has_output = false;
/**
* Universal cache
*
* @var array
*/
public $cache = array();
/** /**
* Strip preg pattern * Strip preg pattern
* *
@@ -386,7 +393,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->prefix_code = array(); $this->prefix_code = array();
$_compiled_code = ''; $_compiled_code = '';
// get template source // get template source
$_content = $this->template->source->content; $_content = $this->template->source->getContent();
if ($_content != '') { if ($_content != '') {
// run pre filter if required // run pre filter if required
if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) {
@@ -429,8 +436,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_compiled_code .= $this->templateFunctionCode; $_compiled_code .= $this->templateFunctionCode;
} }
} }
// unset content because template inheritance could have replace source with parent code
unset ($template->source->content);
$this->parent_compiler = null; $this->parent_compiler = null;
$this->template = null; $this->template = null;
return $_compiled_code; return $_compiled_code;
@@ -955,7 +960,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public function getVariableName($input) public function getVariableName($input)
{ {
if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]~', $input, $match)) { if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) {
return $match[1]; return $match[1];
} }
return false; return false;