Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 36bb08f

Browse files
sarciszewskifabpot
authored andcommitted
Update StringUtils.php
1 parent 5baa642 commit 36bb08f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Core/Util/StringUtils.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ public static function equals($knownString, $userInput)
7272
*/
7373
public static function safeStrlen($string)
7474
{
75-
if (function_exists('mb_strlen')) {
75+
// Premature optimization
76+
// Since this cannot be changed at runtime, we can cache it
77+
static $func_exists = null;
78+
if ($func_exists === null) {
79+
$func_exists = function_exists('mb_strlen');
80+
}
81+
82+
if ($func_exists) {
7683
return mb_strlen($string, '8bit');
7784
}
7885

0 commit comments

Comments
 (0)