Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Another sum to beat the generic algo (30% faster)
  • Loading branch information
lizmat committed Nov 15, 2015
1 parent 01747cb commit 8ddc787
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/List.pm
Expand Up @@ -284,6 +284,15 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
method to() { self.elems ?? self[self.end].to !! Nil }
method from() { self.elems ?? self[0].from !! Nil }

method sum() {
my int $elems = self.elems;
my $list := nqp::getattr(self,List,'$!reified');
my $sum = 0;
my int $i = -1;
$sum = $sum + nqp::atpos($list,$i) while ($i = $i + 1) < $elems;
$sum
}

method fmt($format = '%s', $separator = ' ') {
self.map({ .fmt($format) }).join($separator);
}
Expand Down

0 comments on commit 8ddc787

Please sign in to comment.