Skip to content

Commit

Permalink
Streaming CURF!matching-dist
Browse files Browse the repository at this point in the history
In the same way as CURS!matching-dist
  • Loading branch information
lizmat committed Apr 6, 2022
1 parent 32b7d33 commit fe829e0
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/core.c/CompUnit/Repository/FileSystem.pm6
Expand Up @@ -2,9 +2,9 @@ class CompUnit::Repository::FileSystem
does CompUnit::Repository::Locally
does CompUnit::Repository
{
has $!lock = Lock.new;
has $!lock;
has %!loaded; # cache compunit lookup for self.need(...)
has %!seen; # cache distribution lookup for self!matching-dist(...)
has $!seen; # cache distribution lookup for self!matching-dist(...)
has $!precomp;
has $!id;
has $!precomp-stores;
Expand All @@ -14,18 +14,23 @@ class CompUnit::Repository::FileSystem

my constant @extensions = <.rakumod .pm6 .pm>;

method !matching-dist(CompUnit::DependencySpecification $spec) {
$!lock.protect: {
return $_ with %!seen{~$spec};
}
method TWEAK(--> Nil) {
$!lock := Lock.new;
$!seen := nqp::hash;
}

with self.candidates($spec).head {
$!lock.protect: {
return %!seen{~$spec} //= $_;
}
# An equivalent of self.candidates($spec).head that caches the best match
method !matching-dist(CompUnit::DependencySpecification:D $spec) {
$!lock.protect: {
nqp::ifnull(
nqp::atkey($!seen,~$spec),
nqp::if(
(my $candidate := self.candidates($spec).head),
nqp::bindkey($!seen,~$spec,$candidate),
Nil
)
)
}

Nil
}

method !comp-unit-id($name) {
Expand Down

0 comments on commit fe829e0

Please sign in to comment.