Skip to content

Commit

Permalink
Streamline CU::PrecompilationDependency::File.deserialize
Browse files Browse the repository at this point in the history
- specify attributes more strictly
- use .new for new object, including serialized-spec
  • Loading branch information
lizmat committed Mar 10, 2020
1 parent 11b186c commit dec40dc
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/core.c/CompUnit/PrecompilationUnit.pm6
Expand Up @@ -84,29 +84,27 @@ role CompUnit::PrecompilationUnit {
}
}

class CompUnit::PrecompilationDependency::File does CompUnit::PrecompilationDependency {
has CompUnit::PrecompilationId $.id;
has Str $.src;
has Str $.checksum is rw;
has Str $!serialized-spec;
has CompUnit::DependencySpecification $.spec;
class CompUnit::PrecompilationDependency::File
does CompUnit::PrecompilationDependency
{
has CompUnit::PrecompilationId $.id is built(:bind);
has CompUnit::DependencySpecification $.spec is built(:bind);
has Str $.src is built(:bind);
has Str $.checksum is rw;
has Str $!serialized-spec is built(:bind);

method source-name() {
"$.src ($.spec.short-name())"
}

method deserialize(str $str) {
my $parts := nqp::split("\0", $str);
nqp::p6bindattrinvres(
self.new(
:id(CompUnit::PrecompilationId.new-without-check(nqp::atpos($parts, 0))),
:src(nqp::atpos($parts, 1)),
:checksum(nqp::atpos($parts, 2))
),
CompUnit::PrecompilationDependency::File,
'$!serialized-spec',
nqp::atpos($parts, 3),
);
my $parts := nqp::split("\0",$str);
self.new(
:id(CompUnit::PrecompilationId.new-without-check(nqp::atpos($parts,0))),
:src(nqp::atpos($parts,1)),
:checksum(nqp::atpos($parts,2))
:serialized-spec(nqp::atpos($parts,3))
)
}

method spec(--> CompUnit::DependencySpecification:D) {
Expand Down

0 comments on commit dec40dc

Please sign in to comment.