Skip to content
Permalink
Browse files

Make Iterable (<=) 2..3x faster

- 2x as fast on object hashes
- 3x as fast on normal hashes
  • Loading branch information...
lizmat committed May 8, 2019
1 parent 3556f27 commit 44a6468f96995b1ca50c2c88d6fc3bc74f9502bc
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/core/set_subset.pm6
@@ -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 }

0 comments on commit 44a6468

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