From e4f3358fa81b8359fab2eb4dd3fb32e8eace8799 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Mon, 26 Jun 2017 01:04:19 +0200 Subject: [PATCH] Make Any (-) Map|Iterable about 2x faster - because the right hand side no longer gets coerced to a Set first - but instead is handled on-the-fly - possibly without any iteration if the left is equivalent to an empty Set --- src/core/set_operators.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/set_operators.pm b/src/core/set_operators.pm index f5cbc0013df..af77c0d62f6 100644 --- a/src/core/set_operators.pm +++ b/src/core/set_operators.pm @@ -457,6 +457,9 @@ multi sub infix:<(-)>(Mixy:D $a, QuantHash:D $b) { multi sub infix:<(-)>(QuantHash:D $a, Mixy:D $b) { Rakudo::QuantHash.DIFFERENCE-MIXY-QUANTHASH($a.Mix, $b) } +multi sub infix:<(-)>(Mixy:D $a, Map:D $b) { + Rakudo::QuantHash.DIFFERENCE-MIXY-QUANTHASH($a, $b.Set) +} multi sub infix:<(-)>(Mixy:D $a, Any:D $b) { # also Iterable Rakudo::QuantHash.DIFFERENCE-MIXY-QUANTHASH($a, $b.Set) } @@ -475,12 +478,18 @@ multi sub infix:<(-)>(Baggy:D $a, QuantHash:D $b) { multi sub infix:<(-)>(QuantHash:D $a, Baggy:D $b) { Rakudo::QuantHash.DIFFERENCE-BAGGY-QUANTHASH($a.Bag, $b) } +multi sub infix:<(-)>(Baggy:D $a, Map:D $b) { + Rakudo::QuantHash.DIFFERENCE-BAGGY-QUANTHASH($a, $b.Set) +} multi sub infix:<(-)>(Baggy:D $a, Any:D $b) { # also Iterable Rakudo::QuantHash.DIFFERENCE-BAGGY-QUANTHASH($a, $b.Set) } multi sub infix:<(-)>(Any:D $a, Baggy:D $b) { Rakudo::QuantHash.DIFFERENCE-BAGGY-QUANTHASH($a.Bag, $b) } +multi sub infix:<(-)>(Any:D $a, Map:D $b) { infix:<(-)>($a.Set, $b) } +multi sub infix:<(-)>(Any:D $a, Iterable:D $b) { infix:<(-)>($a.Set, $b) } +multi sub infix:<(-)>(Any:D $a, Any:D $b) { infix:<(-)>($a.Set, $b.Set) } multi sub infix:<(-)>(**@p) { return set() unless @p;