Skip to content

Commit

Permalink
Simplify Iterable eqv Iterable
Browse files Browse the repository at this point in the history
By removing the specific Positional handling.  This every so lightly
improves performance on comparing arrays, while not affecting any
other performance.

This also removes the use of AT-POS in eqv handling, making it easier
to later introduce proper eqv handling of sparse arrays.
  • Loading branch information
lizmat committed Jun 15, 2021
1 parent 750c5d0 commit 168da39
Showing 1 changed file with 23 additions and 43 deletions.
66 changes: 23 additions & 43 deletions src/core.c/Iterable.pm6
Expand Up @@ -110,51 +110,31 @@ multi sub infix:<eqv>(Iterable:D \a, Iterable:D \b) {
nqp::if( # not same object
nqp::eqaddr(a.WHAT,b.WHAT),
nqp::if( # same type
nqp::istype(a, Positional),
nqp::if( # Positional
a.is-lazy,
nqp::if( # a lazy
b.is-lazy,
Any.throw-iterator-cannot-be-lazy('eqv','') # a && b lazy
),
nqp::if( # a NOT lazy
b.is-lazy,
0, # b lazy
nqp::if( # a && b NOT lazy
nqp::iseq_i((my int $elems = a.elems),b.elems),
nqp::stmts( # same # elems
(my int $i = -1),
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems) # not exhausted
&& a.AT-POS($i) eqv b.AT-POS($i), # still same
nqp::null
),
nqp::iseq_i($i,$elems) # exhausted = success!
)
)
)
nqp::iseq_i(
nqp::istrue(my \ial := (my \ia := a.iterator).is-lazy),
nqp::istrue( (my \ib := b.iterator).is-lazy)
),
nqp::if( # NOT Positional
nqp::iseq_i(
(my \ia := a.iterator).is-lazy,
(my \ib := b.iterator).is-lazy
),
nqp::if(
ia.is-lazy,
Any.throw-iterator-cannot-be-lazy('eqv',''),
nqp::stmts(
nqp::until(
nqp::stmts(
(my \pa := ia.pull-one),
(my \pb := ib.pull-one),
nqp::eqaddr(pa,IterationEnd)
|| nqp::eqaddr(pb,IterationEnd)
|| nqp::not_i(pa eqv pb)
),
nqp::null
nqp::if(
ial,
Any.throw-iterator-cannot-be-lazy('eqv',''),
nqp::stmts(
nqp::if(
nqp::istype(ia,PredictiveIterator)
&& nqp::istype(ib,PredictiveIterator)
&& nqp::isne_i(ia.count-only,ib.count-only),
(return False)
),
nqp::until(
nqp::stmts(
(my \pa := ia.pull-one),
(my \pb := ib.pull-one),
nqp::eqaddr(pa,IterationEnd)
|| nqp::eqaddr(pb,IterationEnd)
|| nqp::isfalse(pa eqv pb)
),
nqp::eqaddr(pa,pb) # both IterationEnd = success!
)
nqp::null
),
nqp::eqaddr(pa,pb) # both IterationEnd = success!
)
)
)
Expand Down

0 comments on commit 168da39

Please sign in to comment.