Skip to content

Commit

Permalink
Save a couple of Scalar allocations per Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jan 15, 2018
1 parent fbf432f commit 4804003
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/Promise.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ my class Promise does Awaitable {
has $!thens;
has Mu $!dynamic_context;

submethod BUILD(:$!scheduler = $*SCHEDULER --> Nil) {
submethod BUILD(:$scheduler = $*SCHEDULER --> Nil) {
$!scheduler := $scheduler;
$!lock := nqp::create(Lock);
$!cond := $!lock.condition();
$!status = Planned;
$!status := Planned;
$!thens := nqp::list();
}

Expand Down Expand Up @@ -91,7 +92,7 @@ my class Promise does Awaitable {
method !keep(Mu \result --> Nil) {
$!lock.protect({
$!result := result;
$!status = Kept;
$!status := Kept;
self!schedule_thens();
$!cond.signal_all;
});
Expand Down Expand Up @@ -122,7 +123,7 @@ my class Promise does Awaitable {
$!result = nqp::istype(result, Exception)
?? result
!! X::AdHoc.new(payload => result);
$!status = Broken;
$!status := Broken;
self!schedule_thens();
$!cond.signal_all;
});
Expand Down Expand Up @@ -158,7 +159,7 @@ my class Promise does Awaitable {
}

method cause(Promise:D:) {
my $status = $!status;
my $status := $!status;
if $status == Broken {
$!result
} else {
Expand Down

0 comments on commit 4804003

Please sign in to comment.