Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add two arg candidates to infix min and max
This is about 30x faster for the idiom: c = a min b, because we do not
have to allocate a slurpy array just to iterate over it.
For http://rosettacode.org/wiki/Draw_a_sphere#Perl_6 it results in a total
speedup of about 44%.
  • Loading branch information
FROGGS committed Oct 29, 2014
1 parent 560a8b0 commit 7474012
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/Any.pm
Expand Up @@ -443,6 +443,9 @@ multi postfix:<-->(Mu:U \a is rw) { a = -1; 0 }

# builtins
proto infix:<min>(|) is pure { * }
multi infix:<min>(Mu:D \a, Mu:U) { a }
multi infix:<min>(Mu:U, Mu:D \b) { b }
multi infix:<min>(Mu:D \a, Mu:D \b) { (a cmp b) < 0 ?? a !! b }
multi infix:<min>(*@args) { @args.min }
# XXX the multi version suffers from a multi dispatch bug
# where the mandatory named is ignored in the presence of a slurpy
Expand All @@ -452,6 +455,9 @@ multi infix:<min>(*@args) { @args.min }
sub min(*@args, :&by = &infix:<cmp>) { @args.min(&by) }

proto infix:<max>(|) is pure { * }
multi infix:<max>(Mu:D \a, Mu:U) { a }
multi infix:<max>(Mu:U, Mu:D \b) { b }
multi infix:<max>(Mu:D \a, Mu:D \b) { (a cmp b) > 0 ?? a !! b }
multi infix:<max>(*@args) { @args.max }
#proto sub max(|) { * }
#multi sub max(*@args) { @args.max() }
Expand Down

0 comments on commit 7474012

Please sign in to comment.