Skip to content

Commit

Permalink
[8.x] increase performance of Str::before by over 60%. (#34642)
Browse files Browse the repository at this point in the history
* [8.x] increase performance of Str::before by over 50%.

* [8.x] refactor code for readability and a further 10% speed gain.
  • Loading branch information
lupinitylabs authored Oct 5, 2020
1 parent 0612709 commit 576dd3d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ public static function ascii($value, $language = 'en')
*/
public static function before($subject, $search)
{
return $search === '' ? $subject : explode($search, $subject)[0];
if ($search === '') {
return $subject;
}

$result = strstr($subject, (string) $search, true);

return $result === false ? $subject : $result;
}

/**
Expand Down

0 comments on commit 576dd3d

Please sign in to comment.