Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

escape modifier could be better optimized

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
Lemon Juice
Smarty Pro


Joined: 24 May 2006
Posts: 109

PostPosted: Tue Apr 20, 2010 10:34 pm    Post subject: escape modifier could be better optimized Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP