Skip to content

Commit af1c4dd

Browse files
authored
Add advice to reword .unique :with using :as when possible
The :with has O(n²/2) complexity and basically slows to a crawl with 2000+ element lists. my @p = 1..3000; @ = @p.unique: :with(&[eqv]); say now - INIT now; # 25.42728348 my @p = 1..3000; @ = @p.unique: :as(*.Str); say now - INIT now; # 0.0185597 say 25.427/.0186; # 1367.043011
1 parent 555bb55 commit af1c4dd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

doc/Type/List.pod6

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ Example:
658658
my @list = {a => 42}, {b => 13}, {a => 42};
659659
say @list.unique(:with(&[eqv])) # OUTPUT: «({a => 42} {b => 13})␤»
660660
661+
B<Note:> since C<:with> L<Callable> has to be tried with all the items in the list,
662+
this makes C<unique> follow a path with much higher algorithmic complexity. You should
663+
try to use the C<:as> argument instead, whenever possible.
664+
661665
=head2 routine repeated
662666
663667
Defined as:

0 commit comments

Comments
 (0)