From fe829e075fde48c5337c75c2eb924e8cd2c3c828 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Wed, 6 Apr 2022 16:27:21 +0200 Subject: [PATCH] Streaming CURF!matching-dist In the same way as CURS!matching-dist --- src/core.c/CompUnit/Repository/FileSystem.pm6 | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/core.c/CompUnit/Repository/FileSystem.pm6 b/src/core.c/CompUnit/Repository/FileSystem.pm6 index b759f450441..c9c51326358 100644 --- a/src/core.c/CompUnit/Repository/FileSystem.pm6 +++ b/src/core.c/CompUnit/Repository/FileSystem.pm6 @@ -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; @@ -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) {