mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
optimize compilation of merged subtemplates
This commit is contained in:
@@ -210,18 +210,20 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) {
|
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) {
|
||||||
$compiler->smarty->allow_ambiguous_resources = true;
|
$compiler->smarty->allow_ambiguous_resources = true;
|
||||||
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
|
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
|
||||||
// save unique function name
|
|
||||||
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->compiled->unifunc = 'content_' .
|
|
||||||
str_replace(array('.', ','), '_', uniqid('', true));
|
|
||||||
if ($compiler->inheritance) {
|
|
||||||
$tpl->compiler->inheritance = true;
|
|
||||||
}
|
|
||||||
// make sure whole chain gets compiled
|
|
||||||
$tpl->mustCompile = true;
|
|
||||||
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
|
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
|
||||||
|
$tpl->compiled = new Smarty_Template_Compiled();
|
||||||
|
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
||||||
|
$tpl->loadCompiler();
|
||||||
|
// save unique function name
|
||||||
|
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->compiled->unifunc = 'content_' .
|
||||||
|
str_replace(array('.', ','), '_', uniqid('', true));
|
||||||
|
if ($compiler->inheritance) {
|
||||||
|
$tpl->compiler->inheritance = true;
|
||||||
|
}
|
||||||
|
// make sure whole chain gets compiled
|
||||||
|
$tpl->mustCompile = true;
|
||||||
$tpl->compiler->suppressTemplatePropertyHeader = true;
|
$tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||||
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->compiled->nocache_hash = str_replace(array('.',
|
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->compiled->nocache_hash;
|
||||||
','), '_', uniqid(rand(), true));
|
|
||||||
// get compiled code
|
// get compiled code
|
||||||
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
|
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
|
||||||
unset($tpl->compiler);
|
unset($tpl->compiler);
|
||||||
@@ -263,10 +265,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
|
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
|
||||||
$_compile_id != '$_smarty_tpl->compile_id';
|
$_compile_id != '$_smarty_tpl->compile_id';
|
||||||
if ($has_compiled_template && !$call_nocache) {
|
if ($has_compiled_template && !$call_nocache) {
|
||||||
// if ($has_compiled_template && !$compiler->tag_nocache && !$compiler->nocache) {
|
|
||||||
// never call inline templates in nocache mode
|
|
||||||
//$compiler->suppressNocacheProcessing = true;
|
|
||||||
$_hash = $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'];
|
|
||||||
$_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
|
$_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
|
||||||
if ($update_compile_id) {
|
if ($update_compile_id) {
|
||||||
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
||||||
@@ -277,9 +275,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
//$compiler->suppressNocacheProcessing = true;
|
//$compiler->suppressNocacheProcessing = true;
|
||||||
}
|
}
|
||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}'));\n";
|
$_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}'));\n";
|
||||||
} else {
|
} else {
|
||||||
$_output .= "echo \$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}');\n";
|
$_output .= "echo \$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}');\n";
|
||||||
}
|
}
|
||||||
if ($update_compile_id) {
|
if ($update_compile_id) {
|
||||||
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
|
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
|
||||||
|
@@ -539,13 +539,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*
|
*
|
||||||
* @returns object template content
|
* @returns object template content
|
||||||
*/
|
*/
|
||||||
public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl, $hash, $content_func)
|
public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl, $content_func)
|
||||||
{
|
{
|
||||||
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl);
|
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl);
|
||||||
if (!isset($tpl->compiled)) {
|
if (!isset($tpl->compiled)) {
|
||||||
$tpl->compiled = $this->compiled;
|
$tpl->compiled = $this->compiled;
|
||||||
}
|
}
|
||||||
$tpl->compiled->nocache_hash = $hash;
|
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::start_template($tpl);
|
Smarty_Internal_Debug::start_template($tpl);
|
||||||
Smarty_Internal_Debug::start_render($tpl);
|
Smarty_Internal_Debug::start_render($tpl);
|
||||||
|
Reference in New Issue
Block a user