Skip to content
Permalink
Browse files

Initialize CU:RepositoryRegistry at setting compile time

There is no need to go through the motions of adding a CU:Repository
thread-safely *each* time at startup when we can also do this at
setting compile time.  This should help a bit with startup times.
  • Loading branch information...
lizmat committed Oct 9, 2018
1 parent 7e86d4e commit 0425d927f8fbda07b8d9ce5efdd83f50d53381e0
Showing with 18 additions and 16 deletions.
  1. +18 −16 src/core/CompUnit/RepositoryRegistry.pm6
@@ -7,6 +7,7 @@ class CompUnit::Repository::Perl5 { ... }

#?if jvm
class CompUnit::Repository::JavaRuntime { ... }
class CompUnit::Repository::Java { ... }
#?endif

class CompUnit::RepositoryRegistry {
@@ -335,13 +336,25 @@ class CompUnit::RepositoryRegistry {
}
}

sub short-id2class(Str:D $short-id) is rw {
state %short-id2class;
state $lock = Lock.new;
# No need to do difficult things at startup when we can precompile this
# into the setting.
BEGIN my %short-id2class = (
'file', CompUnit::Repository::FileSystem,
'inst', CompUnit::Repository::Installation,
'ap', CompUnit::Repository::AbsolutePath,
'nqp', CompUnit::Repository::NQP,
'perl5', CompUnit::Repository::Perl5,
#?if jvm
'javart', CompUnit::Repository::JavaRuntime,
'java', CompUnit::Repository::Java,
#?endif
);
my $sid-lock := Lock.new;

sub short-id2class(Str:D $short-id) is rw {
Proxy.new(
FETCH => {
$lock.protect( {
$sid-lock.protect( {
if %short-id2class.EXISTS-KEY($short-id) {
%short-id2class.AT-KEY($short-id);
}
@@ -369,22 +382,11 @@ class CompUnit::RepositoryRegistry {
STORE => -> $, $class {
my $type = ::($class);
die "Must load class '$class' first" if nqp::istype($type,Failure);
$lock.protect( { %short-id2class{$short-id} := $type } );
$sid-lock.protect( { %short-id2class{$short-id} := $type } );
},
);
}

# prime the short-id -> class lookup
short-id2class('file') = 'CompUnit::Repository::FileSystem';
short-id2class('inst') = 'CompUnit::Repository::Installation';
short-id2class('ap') = 'CompUnit::Repository::AbsolutePath';
short-id2class('nqp') = 'CompUnit::Repository::NQP';
short-id2class('perl5') = 'CompUnit::Repository::Perl5';
#?if jvm
short-id2class('javart') = 'CompUnit::Repository::JavaRuntime';
short-id2class('java') = 'CompUnit::Repository::Java';
#?endif

sub parse-include-specS(Str:D $specs) {
my @found;
my $default-short-id = 'file';

0 comments on commit 0425d92

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