From d6d2e00423bcf48ea6ba48415b28abf434b45d4f Mon Sep 17 00:00:00 2001 From: Kris Kelly Date: Fri, 9 Sep 2016 23:03:12 +0100 Subject: [PATCH 1/2] 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. --- src/Illuminate/Support/Str.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index e0e3f3e526ea..2d02773c348d 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -86,8 +86,8 @@ 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))) { + foreach ( (array) $needles as $needle ) { + if ( (string) $needle === substr( $haystack, - strlen( $needle ) ) ) { return true; } } @@ -402,8 +402,8 @@ public static function snake($value, $delimiter = '_') */ public static function startsWith($haystack, $needles) { - foreach ((array) $needles as $needle) { - if ($needle != '' && mb_strpos($haystack, $needle) === 0) { + foreach ( (array) $needles as $needle ) { + if ( $needle != '' && substr( $haystack, 0, strlen( $needle ) ) === $needle ) { return true; } } From 8c14e35e05017dbaf6de54cb3ee5b1f7bd28b889 Mon Sep 17 00:00:00 2001 From: Kris Kelly Date: Fri, 9 Sep 2016 23:12:41 +0100 Subject: [PATCH 2/2] removed spacing between parenthesis --- src/Illuminate/Support/Str.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 2d02773c348d..65c616a1fc0d 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -86,8 +86,8 @@ public static function contains($haystack, $needles) */ public static function endsWith($haystack, $needles) { - foreach ( (array) $needles as $needle ) { - if ( (string) $needle === substr( $haystack, - strlen( $needle ) ) ) { + foreach ((array) $needles as $needle) { + if ((string) $needle === substr($haystack, - strlen($needle))) { return true; } } @@ -402,8 +402,8 @@ public static function snake($value, $delimiter = '_') */ public static function startsWith($haystack, $needles) { - foreach ( (array) $needles as $needle ) { - if ( $needle != '' && substr( $haystack, 0, strlen( $needle ) ) === $needle ) { + foreach ((array) $needles as $needle) { + if ($needle != '' && substr($haystack, 0, strlen($needle)) === $needle) { return true; } }