Skip to content
Permalink
Browse files

Streamline short-id2class handling

  • Loading branch information...
lizmat committed Dec 26, 2018
1 parent 5540212 commit 7d3b7e1111c84f856a9d700d522a6af46ae48d4a
Showing with 22 additions and 26 deletions.
  1. +22 −26 src/core/CompUnit/RepositoryRegistry.pm6
@@ -341,7 +341,7 @@ class CompUnit::RepositoryRegistry {
}
}

my %short-id2class = (
my constant $short-id2class = nqp::hash(
'file', CompUnit::Repository::FileSystem,
'inst', CompUnit::Repository::Installation,
'ap', CompUnit::Repository::AbsolutePath,
@@ -361,34 +361,30 @@ class CompUnit::RepositoryRegistry {
Proxy.new(
FETCH => {
$sid-lock.protect( {
if %short-id2class.EXISTS-KEY($short-id) {
%short-id2class.AT-KEY($short-id);
}
else {
my $type = try ::($short-id);
if $type !=== Any {
if $type.?short-id -> $id {
if %short-id2class.EXISTS-KEY($id) {
%short-id2class.AT-KEY($id);
}
else {
%short-id2class.BIND-KEY($id, $type);
}
}
else {
die "Class '$type.^name()' is not a CompUnit::Repository";
}
}
else {
Any
}
}
nqp::ifnull(
nqp::atkey($short-id2class,$short-id),
nqp::if(
nqp::istype((my \type := ::($short-id)),Failure),
(type.defined || Any), # no unhandled Failure warnings
nqp::if(
nqp::can(type,"short-id")
&& (my str $id = type.short-id),
nqp::ifnull(
nqp::atkey($short-id2class,$id),
nqp::bindkey($short-id2class,$id,type)
),
(die "Class '{type.^name}' is not a 'CompUnit::Repository'")
)
)
)
} );
},
STORE => -> $, $class {
my $type = ::($class);
die "Must load class '$class' first" if nqp::istype($type,Failure);
$sid-lock.protect( { %short-id2class{$short-id} := $type } );
nqp::istype((my \type = ::($class)),Failure)
?? (die "Must load class '$class' first")
!! $sid-lock.protect: {
nqp::bindkey($short-id2class,$short-id,type)
}
},
);
}

0 comments on commit 7d3b7e1

Please sign in to comment.
You can’t perform that action at this time.