Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rewrite of List.(uniq|squish) using map()

For "my @a=1..100000; my @b= @a.(uniq|squish) the improvements were:
  uniq:   CPU from 0m23.214s to 0m10.107s  (aka 56% less CPU)
  squish: CPU from 0m10.911s to 0m7.790s   (aka 28% less CPU)
  • Loading branch information...
commit 624ff76ca66f39d96878fbf201ebbedc9c6a7d6b 1 parent 099f0b3
@lizmat lizmat authored
Showing with 16 additions and 7 deletions.
  1. +16 −7 src/core/List.pm
View
23 src/core/List.pm
@@ -328,20 +328,29 @@ my class List does Positional {
method uniq() {
my $seen := nqp::hash();
my str $which;
- gather sink for @.list {
+ map {
$which = nqp::unbox_s($_.WHICH);
- unless nqp::existskey($seen, $which) {
- take $_;
+ if nqp::existskey($seen, $which) {
+ Nil;
+ }
+ else {
nqp::bindkey($seen, $which, 1);
+ $_;
}
- }
+ }, @.list;
}
-
my @secret;
method squish() {
my $last = @secret;
- my $grepped;
- grep { $grepped = $_ !=== $last; $last = $_; $grepped }, @.list;
+ map {
+ if $_ !=== $last {
+ $last = $_;
+ $_;
+ }
+ else {
+ Nil;
+ }
+ }, @.list;
}
multi method gist(List:D:) { join ' ', map { $_.gist }, @(self) }

0 comments on commit 624ff76

Please sign in to comment.
Something went wrong with that request. Please try again.