Skip to content

Commit

Permalink
[5.3] Changed startsWith and endsWith to use substr (non mbstring) (#…
Browse files Browse the repository at this point in the history
…15380)

* Changed startsWith and endsWith to use substr (non mbstring), this is ok here because it doesn't
matter whether it's multi-byte unicode chars or not, just that the same number of bytes match at
the start or the end.

The performance of the existing methods becomes increasingly slow with larger strings due to
 mbstring functions.

* removed spacing between parenthesis
  • Loading branch information
Perturbatio authored and taylorotwell committed Sep 11, 2016
1 parent 5c68fa0 commit 9007318
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function contains($haystack, $needles)
public static function endsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ((string) $needle === static::substr($haystack, -static::length($needle))) {
if ((string) $needle === substr($haystack, - strlen($needle))) {
return true;
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ public static function snake($value, $delimiter = '_')
public static function startsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle != '' && mb_strpos($haystack, $needle) === 0) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === $needle) {
return true;
}
}
Expand Down

0 comments on commit 9007318

Please sign in to comment.