Skip to content

Commit

Permalink
Make Iterable (<=) 2..3x faster
Browse files Browse the repository at this point in the history
- 2x as fast on object hashes
- 3x as fast on normal hashes
  • Loading branch information
lizmat committed May 8, 2019
1 parent 3556f27 commit 44a6468
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/core/set_subset.pm6
Expand Up @@ -128,6 +128,36 @@ multi sub infix:<<(<=)>>(Map:D \a, Map:D \b --> Bool:D) {
)
}

multi sub infix:<<(<=)>>(Iterable:D \a, Map:D \b --> Bool:D) {
my \iterator := a.iterator;
my \braw := nqp::getattr(nqp::decont(b),Map,'$!storage');

if nqp::eqaddr(b.keyof,Str(Any)) {
nqp::until(
nqp::eqaddr((my \string := iterator.pull-one),IterationEnd),
nqp::unless(
nqp::existskey(braw,my str $key = string.Str)
&& nqp::istrue(nqp::atkey(braw,$key)),
(return False)
)
);
True
}
else {
nqp::until(
nqp::eqaddr((my \object := iterator.pull-one),IterationEnd),
nqp::unless(
nqp::existskey(braw,my str $key = object.WHICH)
&& nqp::istrue(
nqp::getattr(nqp::atkey(braw,$key),Pair,'$!value')
),
(return False)
)
);
True
}
}

multi sub infix:<<(<=)>>(Any \a, Mixy:D \b --> Bool:D) { a.Mix (<=) b }
multi sub infix:<<(<=)>>(Any \a, Baggy:D \b --> Bool:D) { a.Bag (<=) b }
multi sub infix:<<(<=)>>(Any \a, Setty:D \b --> Bool:D) { a.Set (<=) b }
Expand Down

0 comments on commit 44a6468

Please sign in to comment.