- performance require_once should be called only once for shared plugins https://github.com/smarty-php/smarty/issues/280

This commit is contained in:
uwetews
2016-09-02 01:08:50 +02:00
parent 5580857d9b
commit e1d27d68d7
13 changed files with 50 additions and 41 deletions

View File

@@ -1,4 +1,7 @@
===== 3.1.31-dev ===== (xx.xx.xx) ===== 3.1.31-dev ===== (xx.xx.xx)
01.09.2016
- performance require_once should be called only once for shared plugins https://github.com/smarty-php/smarty/issues/280
26.08.2016 26.08.2016
- bugfix change of 23.08.2016 failed on linux when use_include_path = true - bugfix change of 23.08.2016 failed on linux when use_include_path = true

View File

@@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.31-dev/7'; const SMARTY_VERSION = '3.1.31-dev/8';
/** /**
* define variable scopes * define variable scopes

View File

@@ -38,6 +38,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
if (is_null($content)) { if (is_null($content)) {
return; return;
} }
if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
}
$style = null; $style = null;
$indent = 0; $indent = 0;
@@ -92,7 +95,6 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
} }
// wordwrap sentences // wordwrap sentences
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
$_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
} else { } else {
$_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);

View File

@@ -45,7 +45,9 @@
*/ */
function smarty_function_html_checkboxes($params, $template) function smarty_function_html_checkboxes($params, $template)
{ {
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$name = 'checkbox'; $name = 'checkbox';
$values = null; $values = null;

View File

@@ -38,7 +38,9 @@
*/ */
function smarty_function_html_image($params, $template) function smarty_function_html_image($params, $template)
{ {
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$alt = ''; $alt = '';
$file = ''; $file = '';

View File

@@ -35,7 +35,9 @@
*/ */
function smarty_function_html_options($params) function smarty_function_html_options($params)
{ {
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$name = null; $name = null;
$values = null; $values = null;

View File

@@ -45,7 +45,9 @@
*/ */
function smarty_function_html_radios($params, $template) function smarty_function_html_radios($params, $template)
{ {
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$name = 'radio'; $name = 'radio';
$values = null; $values = null;

View File

@@ -6,15 +6,6 @@
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/**
* @ignore
*/
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
/**
* @ignore
*/
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
/** /**
* Smarty {html_select_date} plugin * Smarty {html_select_date} plugin
* Type: function<br> * Type: function<br>
@@ -52,6 +43,12 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
*/ */
function smarty_function_html_select_date($params) function smarty_function_html_select_date($params)
{ {
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
}
// generate timestamps used for month names only // generate timestamps used for month names only
static $_month_timestamps = null; static $_month_timestamps = null;
static $_current_year = null; static $_current_year = null;

View File

@@ -6,15 +6,6 @@
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/**
* @ignore
*/
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
/**
* @ignore
*/
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
/** /**
* Smarty {html_select_time} function plugin * Smarty {html_select_time} function plugin
* Type: function<br> * Type: function<br>
@@ -33,6 +24,12 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
*/ */
function smarty_function_html_select_time($params) function smarty_function_html_select_time($params)
{ {
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
}
$prefix = "Time_"; $prefix = "Time_";
$field_array = null; $field_array = null;
$field_separator = "\n"; $field_separator = "\n";

View File

@@ -32,10 +32,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
if ($format === null) { if ($format === null) {
$format = Smarty::$_DATE_FORMAT; $format = Smarty::$_DATE_FORMAT;
} }
/**
* require_once the {@link shared.make_timestamp.php} plugin
*/
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') { if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string); $timestamp = smarty_make_timestamp($string);
} elseif ($default_date != '') { } elseif ($default_date != '') {
@@ -44,7 +40,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
return; return;
} }
if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) { if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
if (DIRECTORY_SEPARATOR == '\\') { if (Smarty::$_IS_WINDOWS) {
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if (strpos($format, '%e') !== false) { if (strpos($format, '%e') !== false) {

View File

@@ -116,7 +116,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'hexentity': case 'hexentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$return = ''; $return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#x' . strtoupper(dechex($unicode)) . ';'; $return .= '&#x' . strtoupper(dechex($unicode)) . ';';
@@ -135,7 +137,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'decentity': case 'decentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$return = ''; $return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#' . $unicode . ';'; $return .= '&#' . $unicode . ';';
@@ -158,8 +162,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'mail': case 'mail':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
}
return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
} }
// no MBString fallback // no MBString fallback
@@ -169,7 +174,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// escape non-standard chars, such as ms document quotes // escape non-standard chars, such as ms document quotes
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) { if ($unicode >= 126) {
$return .= '&#' . $unicode . ';'; $return .= '&#' . $unicode . ';';

View File

@@ -25,8 +25,9 @@
function smarty_modifier_replace($string, $search, $replace) function smarty_modifier_replace($string, $search, $replace)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
}
return smarty_mb_str_replace($search, $replace, $string); return smarty_mb_str_replace($search, $replace, $string);
} }

View File

@@ -6,11 +6,6 @@
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/**
* @ignore
*/
require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* Type: modifier<br> * Type: modifier<br>
@@ -28,6 +23,9 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
function smarty_modifiercompiler_escape($params, $compiler) function smarty_modifiercompiler_escape($params, $compiler)
{ {
static $_double_encode = null; static $_double_encode = null;
if (!is_callable('smarty_literal_compiler_param')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
}
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
} }