Skip to content

Commit 99b3538

Browse files
authored
[7.x] Optimize Str::startsWith() (#32243)
* optimize Str::startsWith by using strncmp * add some tests with characters that are definitely utf8
1 parent cb075f7 commit 99b3538

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Str.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public static function snake($value, $delimiter = '_')
604604
public static function startsWith($haystack, $needles)
605605
{
606606
foreach ((array) $needles as $needle) {
607-
if ((string) $needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
607+
if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) {
608608
return true;
609609
}
610610
}

0 commit comments

Comments
 (0)