Created
January 13, 2018 00:24
-
-
Save lizmat/4e2d05df2f252ce50c1c98a9106375a2 to your computer and use it in GitHub Desktop.
another try at optimizing exit_handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Metamodel/BOOTSTRAP.nqp b/src/Perl6/Metamodel/BOOTSTRAP.nqp | |
index 449f138..ac0e2ad 100644 | |
--- a/src/Perl6/Metamodel/BOOTSTRAP.nqp | |
+++ b/src/Perl6/Metamodel/BOOTSTRAP.nqp | |
@@ -3236,98 +3236,98 @@ nqp::sethllconfig('perl6', nqp::hash( | |
$result | |
}, | |
'exit_handler', -> $coderef, $resultish { | |
+ if nqp::p6inpre { return } | |
+ | |
my %phasers := | |
nqp::getattr(nqp::getcodeobj($coderef),Block,'$!phasers'); | |
- unless nqp::p6inpre() { | |
- my @leaves := nqp::atkey(%phasers, '!LEAVE-ORDER'); | |
- my @posts := nqp::atkey(%phasers, 'POST'); | |
- my @exceptions; | |
- unless nqp::isnull(@leaves) { | |
- my @keeps := nqp::atkey(%phasers, 'KEEP'); | |
- my @undos := nqp::atkey(%phasers, 'UNDO'); | |
- my int $n := nqp::elems(@leaves); | |
- | |
- # only have a single LEAVEish phaser, so no frills needed | |
- if nqp::isnull(@keeps) | |
- && nqp::isnull(@undos) | |
- && nqp::isnull(@posts) | |
- && $n == 1 | |
- { | |
+ my @leaves := nqp::atkey(%phasers, '!LEAVE-ORDER'); | |
+ my @posts := nqp::atkey(%phasers, 'POST'); | |
+ my @exceptions; | |
+ unless nqp::isnull(@leaves) { | |
+ my @keeps := nqp::atkey(%phasers, 'KEEP'); | |
+ my @undos := nqp::atkey(%phasers, 'UNDO'); | |
+ my int $n := nqp::elems(@leaves); | |
+ | |
+ # only have a single LEAVEish phaser, so no frills needed | |
+ if nqp::isnull(@keeps) | |
+ && nqp::isnull(@undos) | |
+ && nqp::isnull(@posts) | |
+ && $n == 1 | |
+ { | |
#?if jvm | |
- nqp::decont(nqp::atpos(@leaves,0))(); | |
+ nqp::decont(nqp::atpos(@leaves,0))(); | |
#?endif | |
#?if moar | |
- nqp::p6capturelexwhere( | |
- nqp::decont(nqp::atpos(@leaves,0)).clone)(); | |
+ nqp::p6capturelexwhere( | |
+ nqp::decont(nqp::atpos(@leaves,0)).clone)(); | |
#?endif | |
- # don't bother to CATCH, there can only be one exception | |
- } | |
+ # don't bother to CATCH, there can only be one exception | |
+ } | |
- # slow path here | |
- else { | |
- my int $i := -1; | |
- my int $run; | |
- my $phaser; | |
- while ++$i < $n { | |
- $phaser := nqp::decont(nqp::atpos(@leaves, $i)); | |
- $run := 1; | |
- unless nqp::isnull(@keeps) { | |
- for @keeps { | |
- if nqp::eqaddr(nqp::decont($_),$phaser) { | |
- $run := !nqp::isnull($resultish) && | |
- nqp::isconcrete($resultish) && | |
- $resultish.defined; | |
- last; | |
- } | |
+ # slow path here | |
+ else { | |
+ my int $i := -1; | |
+ my int $run; | |
+ my $phaser; | |
+ while ++$i < $n { | |
+ $phaser := nqp::decont(nqp::atpos(@leaves, $i)); | |
+ $run := 1; | |
+ unless nqp::isnull(@keeps) { | |
+ for @keeps { | |
+ if nqp::eqaddr(nqp::decont($_),$phaser) { | |
+ $run := !nqp::isnull($resultish) && | |
+ nqp::isconcrete($resultish) && | |
+ $resultish.defined; | |
+ last; | |
} | |
} | |
- unless nqp::isnull(@undos) { | |
- for @undos { | |
- if nqp::eqaddr(nqp::decont($_),$phaser) { | |
- $run := nqp::isnull($resultish) || | |
- !nqp::isconcrete($resultish) || | |
- !$resultish.defined; | |
- last; | |
- } | |
+ } | |
+ unless nqp::isnull(@undos) { | |
+ for @undos { | |
+ if nqp::eqaddr(nqp::decont($_),$phaser) { | |
+ $run := nqp::isnull($resultish) || | |
+ !nqp::isconcrete($resultish) || | |
+ !$resultish.defined; | |
+ last; | |
} | |
} | |
- if $run { | |
+ } | |
+ if $run { | |
#?if jvm | |
- $phaser(); | |
+ $phaser(); | |
#?endif | |
#?if moar | |
- nqp::p6capturelexwhere($phaser.clone())(); | |
+ nqp::p6capturelexwhere($phaser.clone())(); | |
#?endif | |
- CATCH { nqp::push(@exceptions, $_) } | |
- } | |
+ CATCH { nqp::push(@exceptions, $_) } | |
} | |
} | |
} | |
+ } | |
- unless nqp::isnull(@posts) { | |
- my $value := nqp::ifnull($resultish,Mu); | |
- my int $n := nqp::elems(@posts); | |
- my int $i := -1; | |
- while ++$i < $n { | |
+ unless nqp::isnull(@posts) { | |
+ my $value := nqp::ifnull($resultish,Mu); | |
+ my int $n := nqp::elems(@posts); | |
+ my int $i := -1; | |
+ while ++$i < $n { | |
#?if jvm | |
- nqp::atpos(@posts, $i)($value)); | |
+ nqp::atpos(@posts, $i)($value)); | |
#?endif | |
#?if moar | |
- nqp::p6capturelexwhere(nqp::atpos(@posts,$i).clone)($value); | |
+ nqp::p6capturelexwhere(nqp::atpos(@posts,$i).clone)($value); | |
#?endif | |
- CATCH { nqp::push(@exceptions, $_); last; } | |
- } | |
+ CATCH { nqp::push(@exceptions, $_); last; } | |
} | |
+ } | |
- if @exceptions { | |
- if nqp::elems(@exceptions) > 1 { | |
- my %ex := nqp::gethllsym('perl6', 'P6EX'); | |
- if !nqp::isnull(%ex) && nqp::existskey(%ex, 'X::PhaserExceptions') { | |
- nqp::atkey(%ex, 'X::PhaserExceptions')(@exceptions); | |
- } | |
+ if @exceptions { | |
+ if nqp::elems(@exceptions) > 1 { | |
+ my %ex := nqp::gethllsym('perl6', 'P6EX'); | |
+ if !nqp::isnull(%ex) && nqp::existskey(%ex, 'X::PhaserExceptions') { | |
+ nqp::atkey(%ex, 'X::PhaserExceptions')(@exceptions); | |
} | |
- nqp::rethrow(@exceptions[0]); | |
} | |
+ nqp::rethrow(@exceptions[0]); | |
} | |
}, | |
#?if moar | |
diff --git a/src/core/Variable.pm b/src/core/Variable.pm | |
index 23aacd5..8dcb1cd 100644 | |
--- a/src/core/Variable.pm | |
+++ b/src/core/Variable.pm | |
@@ -159,7 +159,7 @@ multi sub trait_mod:<will>(Variable:D $v, $block, :$enter! ) { | |
$v.block.add_phaser('ENTER', $v.willdo($block, 1) ); | |
} | |
multi sub trait_mod:<will>(Variable:D $v, $block, :$leave! ) { | |
- $v.block.add_phaser('LEAVE', $v.willdo($block) ); | |
+ $v.block.add_phaser('LEAVE', $v.willdo($block, 2) ); | |
} | |
multi sub trait_mod:<will>(Variable:D $v, $block, :$keep! ) { | |
$v.block.add_phaser('KEEP', $v.willdo($block)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment