Created
December 6, 2017 20:32
-
-
Save lizmat/be498731d5e6365b629292f01f42cce5 to your computer and use it in GitHub Desktop.
diff destabilizing MoarVM
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/core/multidim_slice.pm b/src/core/multidim_slice.pm | |
index 194d043..5ce42c2 100644 | |
--- a/src/core/multidim_slice.pm | |
+++ b/src/core/multidim_slice.pm | |
@@ -57,30 +57,34 @@ multi sub postcircumfix:<[; ]>(\SELF, @indices) is raw { | |
(my $indices := nqp::getattr(@indices,List,'$!reified')), | |
(my int $elems = nqp::elems($indices)), | |
(my int $i = -1), | |
+ (my $idxs := nqp::list_i), | |
nqp::while( | |
- nqp::islt_i(($i = nqp::add_i($i,1)),$elems) | |
- && nqp::istype(nqp::atpos($indices,$i),Int), | |
- nqp::null | |
- ), | |
- nqp::if( | |
- nqp::islt_i($i,$elems), | |
- MD-ARRAY-SLICE(SELF,@indices), | |
+ nqp::islt_i(($i = nqp::add_i($i,1)),$elems), | |
nqp::if( | |
- nqp::iseq_i($elems,2), | |
- SELF.AT-POS( | |
- nqp::atpos($indices,0), | |
- nqp::atpos($indices,1) | |
- ), | |
+ nqp::istype((my $index := nqp::atpos($indices,$i)),Int), | |
+ nqp::push_i($idxs,$index), # it's an Int, use that | |
nqp::if( | |
- nqp::iseq_i($elems,3), | |
- SELF.AT-POS( | |
- nqp::atpos($indices,0), | |
- nqp::atpos($indices,1), | |
- nqp::atpos($indices,2) | |
- ), | |
- SELF.AT-POS(|@indices) | |
+ nqp::istype($index,Numeric) || nqp::istype($index,Str), | |
+ nqp::push_i($idxs,$index.Int), # can be coerced to Int, use that | |
+ (return-rw MD-ARRAY-SLICE(SELF,@indices)) # alas, slow path needed | |
) | |
) | |
+ ), | |
+ nqp::if( # we have all Ints | |
+ nqp::iseq_i($elems,2), | |
+ SELF.AT-POS( # fast pathing [n;n] | |
+ nqp::atpos_i($idxs,0), | |
+ nqp::atpos_i($idxs,1) | |
+ ), | |
+ nqp::if( | |
+ nqp::iseq_i($elems,3), | |
+ SELF.AT-POS( # fast pathing [n;n;n] | |
+ nqp::atpos_i($idxs,0), | |
+ nqp::atpos_i($idxs,1), | |
+ nqp::atpos_i($idxs,2) | |
+ ), | |
+ SELF.AT-POS(|@indices) # alas >3 dims, slow path | |
+ ) | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment