Skip to content

Commit

Permalink
Performance String Modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoprunners authored Nov 3, 2023
1 parent fd1f02d commit e82b569
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ToolsCore
protected static $file_exists_cache = [];
protected static $_forceCompile;
protected static $_caching;
protected static $_string_modifier;
protected static $_user_plateform;
protected static $_user_browser;
protected static $request;
Expand Down Expand Up @@ -1211,7 +1212,7 @@ public static function str2url($str)
$allow_accented_chars = Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
}

return (new StringModifier())->str2url((string) $str, $allow_accented_chars);
return (self::getStringModifier())->str2url((string) $str, $allow_accented_chars);
}

/**
Expand All @@ -1223,9 +1224,22 @@ public static function str2url($str)
*/
public static function replaceAccentedChars($str)
{
return (new StringModifier())->replaceAccentedChars($str);
return (self::getStringModifier())->replaceAccentedChars($str);
}

/**
* Reuse the StringModifier for performance reasons.
*
* @return StringModifier
*/
private static function getStringModifier()
{
if(!isset(self::$_string_modifier)) {
self::$_string_modifier = new StringModifier();
}
return self::$_string_modifier;
}

/**
* Truncate strings.
*
Expand Down

0 comments on commit e82b569

Please sign in to comment.