Skip to content

Commit

Permalink
Make IO::Spec::Unix.path about 3.5x as fast
Browse files Browse the repository at this point in the history
- don't use gather / take
- use simpler algorithm to check for empty entries
  • Loading branch information
lizmat committed May 24, 2020
1 parent becb85e commit 8dc58ab
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core.c/IO/Spec/Unix.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ my class IO::Spec::Unix is IO::Spec {
}

method path {
(my $p := %*ENV<PATH>) ?? gather {
my int $els = nqp::elems(my $parts := nqp::split(':', $p));
my int $i = -1;
nqp::until(
nqp::iseq_i($els, $i = nqp::add_i($i, 1)),
take nqp::atpos($parts, $i) || '.')
} !! Seq.new(Rakudo::Iterator.Empty)
my $parts := nqp::split(':',%*ENV<PATH>);
my $buffer := nqp::create(IterationBuffer);
my int $i = -1;
nqp::while(
nqp::elems($parts),
nqp::push($buffer,nqp::shift($parts) || ".")
);
$buffer.Seq
}

method splitpath( $path, :$nofile = False ) {
Expand Down

0 comments on commit 8dc58ab

Please sign in to comment.