|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Lemon Juice Smarty Pro
Joined: 24 May 2006 Posts: 109
|
Posted: Tue Apr 20, 2010 10:34 pm Post subject: escape modifier could be better optimized |
|
|
I've just had a look at the smarty_modifier_escape() function and have noticed unnecessary code which only adds to the overhead of the escape modifier. The code begins like that:
Code: |
if (!function_exists('mb_str_replace') && function_exists('mb_strlen')) {
// simulate the missing PHP mb_str_replace function
function mb_str_replace($needle, $replacement, $haystack)
{
$needle_len = mb_strlen($needle);
$replacement_len = mb_strlen($replacement);
$pos = mb_strpos($haystack, $needle, 0);
while ($pos !== false) {
$haystack = mb_substr($haystack, 0, $pos) . $replacement
. mb_substr($haystack, $pos + $needle_len);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
}
return $haystack;
}
}
|
This is necessary only for escape:'mail' type modifier, which is used very rarely. However, the most often used escape of the default type 'html' and all other types as well get slowed down by the initial if and the function call. Why not move the whole if block inside the 'mail' switch statement so that it's only executed when necessary? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|