Permalink
Browse files

RT#82312 - optimize size of numeric range.

Inspired by a patch from Gilbert Röhrbein <payload@lavabit.com>
  • Loading branch information...
coke committed Mar 29, 2013
1 parent 25a9d6d commit 192b28fafdfac66ff40787eae5ef07a3dd918674
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/core/Range.pm
View
@@ -194,6 +194,16 @@ my class Range is Iterable is Cool does Positional {
}
}
}
+
+ multi method Numeric (Range:D:) {
+ nextsame unless $.max ~~ Numeric and $.min ~~ Numeric;
+
+ my $lo := ($.min + $.excludes_min).ceiling;
+ my $hi := ($.max - $.excludes_max).ceiling;
+
+ return 0 if $hi < $lo;
+ return $hi - $lo +1;
+ }
}
sub infix:<..>($min, $max) {

0 comments on commit 192b28f

Please sign in to comment.