Skip to content

Commit

Permalink
Refactor some comparison operators to avoid unnecessary blocks and
Browse files Browse the repository at this point in the history
use of -1 and +1 "constants".
  • Loading branch information
pmichaud committed Aug 6, 2010
1 parent 2c0ea31 commit 035efb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/core/Cool-str.pm
Expand Up @@ -424,11 +424,7 @@ our Str proto sub infix:<x>($str, $n) {
}

our multi sub infix:<cmp>($a, $b) {
if $a eq $b {
0;
} else {
$a lt $b ?? -1 !! 1;
}
$a lt $b ?? Order::Increase !! ($a gt $b ?? Order::Decrease !! Order::Same);
}

our multi sub infix:<leg>($a, $b) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/Numeric.pm
Expand Up @@ -288,19 +288,19 @@ multi sub infix:«!=»(Numeric $a, Numeric $b) {
}

multi sub infix<»(Numeric $a, Numeric $b) {
($a <=> $b) == -1;
($a <=> $b) < 0;
}

multi sub infix>»(Numeric $a, Numeric $b) {
($a <=> $b) == +1;
($a <=> $b) > 0;
}

multi sub infix<=»(Numeric $a, Numeric $b) {
($a <=> $b) != +1;
($a <=> $b) <= 0;
}

multi sub infix>=»(Numeric $a, Numeric $b) {
($a <=> $b) != -1;
($a <=> $b) >= 0;
}

multi sub srand(Numeric $seed) {
Expand Down

0 comments on commit 035efb0

Please sign in to comment.