• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed XenForo_Link - unnecessary double filtering

#1
It's not a real bug, but in Class XenForo_Link, method buildIntegerAndTitleUrlComponent(), there is an apparent unnecessary double call to method getTitleForUrl().
PHP:
$title = self::getTitleForUrl($title, $romanize);
if ($title !== '')
{
    # /item-title.id/ (where delimiter is '.')
    return urlencode(self::getTitleForUrl($title, $romanize)) . XenForo_Application::URL_ID_DELIMITER . intval($integer);
}
I wonder if it could be simplyfied in:
PHP:
$title = self::getTitleForUrl($title, $romanize);
if ($title !== '')
{
    # /item-title.id/ (where delimiter is '.')
    return urlencode($title) . XenForo_Application::URL_ID_DELIMITER . intval($integer);
}
Why filtering two times the same string?
 

Mike

XenForo developer
Staff member
#2
No point in calling it twice, though the value is cached so there's minimal overhead. Thanks.
 
#3
The caching mechanism is not truly effective, because in the second call $title argument is passed already processed, so it could be different than original one.
For example, with your profile member page, first time the function is called with $title = "Mike", second time with $title = "mike", which is not already cached.

I agree it has a very minimal impact in performance terms. The aim of my post was just for cleaning the code.

Anyway, thank you for your work, I think XenForo code is very well written and documented. You guys have done a great work!