Skip to content
Permalink
Browse files

Handle PredictiveIterators a bit better

- one check less per iteration at the expense of a little initial overhead
- throw exception immediately if lengths don't match
  - rather than iterating until one of them is exhausted
  • Loading branch information...
lizmat committed Nov 18, 2018
1 parent f1fa5ad commit 2e5be5b8e4d13664efef24542d041d96681978de
Showing with 26 additions and 1 deletion.
  1. +26 −1 src/core/Hyper.pm6
@@ -196,7 +196,10 @@ class Hyper {
!! self!iterators-left(left-iterator,right-iterator)
!! $!dwim-right
?? self!iterators-right(left-iterator,right-iterator)
!! self!iterators(left-iterator,right-iterator)
!! nqp::istype(left-iterator,PredictiveIterator)
&& nqp::istype(right-iterator,PredictiveIterator)
?? self!predictive-iterators(left-iterator,right-iterator)
!! self!iterators(left-iterator,right-iterator)
;
my \result := nqp::p6bindattrinvres(
nqp::create(
@@ -256,6 +259,28 @@ class Hyper {

#--- Private helper methods ----------------------------------------------------

# ... >>op<< ...
method !predictive-iterators(
PredictiveIterator:D \left,
PredictiveIterator:D \right,
) {
X::HyperOp::NonDWIM.new(
:$!operator,
:left-elems(left.count-only),
:right-elems(right.count-only),
:recursing
).throw
if left.count-only != right.count-only;

# sure they have same number of elems, so only need to check one
my \result := nqp::create(IterationBuffer);
nqp::until(
nqp::eqaddr((my \leftv := left.pull-one),IterationEnd),
nqp::push(result,self.infix(leftv,right.pull-one))
);
result
}

# ... >>op<< ...
method !iterators(Iterator:D \left, Iterator:D \right) {
my \result := nqp::create(IterationBuffer);

0 comments on commit 2e5be5b

Please sign in to comment.
You can’t perform that action at this time.