Skip to content

Commit 48a53be

Browse files
Optimize the execution time of the unique method (#39822)
* Optimize the execution time of the unique method When passing a large array, the unique method is very slow. This modification can increase the speed by hundreds of times, and it is also suitable for most scenarios. * Optimize the execution time of the unique method * Update Collection.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 513d214 commit 48a53be

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,10 @@ public function undot()
14541454
*/
14551455
public function unique($key = null, $strict = false)
14561456
{
1457+
if (is_null($key) && $strict === false) {
1458+
return new static(array_unique($this->items, SORT_REGULAR));
1459+
}
1460+
14571461
$callback = $this->valueRetriever($key);
14581462

14591463
$exists = [];

0 commit comments

Comments
 (0)