1. 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

Discussion in 'Resolved Bug Reports' started by Emanuele I., Jun 3, 2014.

  1. Emanuele I.

    Emanuele I. Member

    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?
     
  2. Mike

    Mike XenForo Developer Staff Member

    No point in calling it twice, though the value is cached so there's minimal overhead. Thanks.
     
  3. Emanuele I.

    Emanuele I. Member

    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!
     

Share This Page