Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Creating a Failure is now more efficient
  • Loading branch information
lizmat committed Feb 15, 2016
1 parent cddf5da commit b5c6a49
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/core/Failure.pm
Expand Up @@ -8,28 +8,27 @@ my class Failure is Nil {
has Int $!handled; # alas, native int breaks on the JVM
#?endif

method !SET-SELF($!exception) {
$!backtrace = $!exception.backtrace || Backtrace.new(5);
$!exception.reset-backtrace;
self
}

multi method new() {
my $stash := CALLER::;
my $payload = $stash<$!>.DEFINITE ?? $stash<$!> !! "Failed";
self.bless(:exception( $payload ~~ Exception
?? $payload !! X::AdHoc.new(:$payload)
))
nqp::create(self)!SET-SELF(
$payload ~~ Exception ?? $payload !! X::AdHoc.new(:$payload)
)
}
multi method new(Exception $exception) {
self.bless(:$exception);
multi method new(Exception:D \exception) {
nqp::create(self)!SET-SELF(exception)
}
multi method new($payload) {
self.bless(:exception( $payload ~~ Exception
?? $payload !! X::AdHoc.new(:$payload)
))
nqp::create(self)!SET-SELF(X::AdHoc.new(:$payload))
}
multi method new(|cap (*@msg)) {
self.bless(:exception(X::AdHoc.from-slurpy(|cap)));
}

submethod BUILD(:$!exception --> Nil) {
$!backtrace = $!exception.backtrace() || Backtrace.new(8);
$!exception.reset-backtrace;
nqp::create(self)!SET-SELF(X::AdHoc.from-slurpy(|cap))
}

# "Shouldn't happen." We use note here because the dynamic scope in GC is likely meaningless.
Expand Down

0 comments on commit b5c6a49

Please sign in to comment.