Skip to content

Commit

Permalink
Streamline .unique(:as) candidate a bit
Browse files Browse the repository at this point in the history
Gives about 3% improvement on a 1000 elem list wth unique values.
  • Loading branch information
lizmat committed Jul 24, 2017
1 parent 12d7d5b commit a636fa8
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/core/Any-iterable-methods.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1557,33 +1557,31 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
}
method new(\list, &as) { nqp::create(self)!SET-SELF(list, &as) }
method pull-one() {
my Mu $value;
my str $needle;
nqp::until(
nqp::eqaddr(($value := $!iter.pull-one),IterationEnd),
nqp::unless(
nqp::existskey($!seen,$needle = nqp::unbox_s(&!as($value).WHICH)),
nqp::stmts(
nqp::bindkey($!seen, $needle, 1),
return $value
nqp::stmts(
nqp::until(
nqp::eqaddr((my $value := $!iter.pull-one),IterationEnd),
nqp::unless(
nqp::existskey($!seen,my $needle := &!as($value).WHICH),
nqp::stmts(
nqp::bindkey($!seen,$needle,1),
return $value
)
)
)
);
IterationEnd
),
IterationEnd
)
}
method push-all($target --> IterationEnd) {
my Mu $value;
my str $needle;
nqp::until(
nqp::eqaddr(($value := $!iter.pull-one),IterationEnd),
nqp::eqaddr((my $value := $!iter.pull-one),IterationEnd),
nqp::unless(
nqp::existskey($!seen,$needle = nqp::unbox_s(&!as($value).WHICH)),
nqp::existskey($!seen,my $needle := &!as($value).WHICH),
nqp::stmts( # doesn't sink
nqp::bindkey($!seen, $needle, 1),
nqp::bindkey($!seen,$needle,1),
$target.push($value)
)
)
);
)
}
}.new(self, &as))
}
Expand Down

0 comments on commit a636fa8

Please sign in to comment.