From 168da39ae24b84f78525280a8d6750dd3cf1a176 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Tue, 15 Jun 2021 09:50:51 +0200 Subject: [PATCH] Simplify Iterable eqv Iterable 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. --- src/core.c/Iterable.pm6 | 66 ++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/core.c/Iterable.pm6 b/src/core.c/Iterable.pm6 index cbf12569e88..d8afcee969a 100644 --- a/src/core.c/Iterable.pm6 +++ b/src/core.c/Iterable.pm6 @@ -110,51 +110,31 @@ multi sub infix:(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! ) ) )