From ba7a37f87027ae08832bb8eee8eb1becd023072c Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 29 Aug 2016 02:33:00 +0200 Subject: [PATCH] Optimize Str random methods by just using strlen() and substr() (#15112) --- src/Illuminate/Support/Str.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 24d308da4be8..2c3a7cbcb376 100755 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -221,12 +221,12 @@ public static function random($length = 16) { $string = ''; - while (($len = static::length($string)) < $length) { + while (($len = strlen($string)) < $length) { $size = $length - $len; $bytes = static::randomBytes($size); - $string .= static::substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); + $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); } return $string; @@ -255,7 +255,7 @@ public static function quickRandom($length = 16) { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - return static::substr(str_shuffle(str_repeat($pool, $length)), 0, $length); + return substr(str_shuffle(str_repeat($pool, $length)), 0, $length); } /**