New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimized Range for getting its size if its a numeric range #2330
Comments
From payload@lavabit.comfixes the problem which you encounter when you try to evaluate ~ payload |
From payload@lavabit.com0001-optimized-Range-for-getting-its-size-if-its-a-numeri.patchFrom b5d95340a193df9af8ccb185c33ef4177a7ab527 Mon Sep 17 00:00:00 2001
From: payload <payload@lavabit.com>
Date: Sun, 16 Jan 2011 19:33:04 +0100
Subject: [PATCH] optimized Range for getting its size if its a numeric range
---
src/core/Range.pm | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/core/Range.pm b/src/core/Range.pm
index fc1395b..8a07b53 100644
--- a/src/core/Range.pm
+++ b/src/core/Range.pm
@@ -103,6 +103,16 @@ class Range is Iterable does Positional {
multi method roll(Whatever) {
self.roll(Inf);
}
+
+ # to optimize the calculation of the size of a big range
+ # +(42..$big) doesnt take too much time now
+ multi method Numeric () {
+ nextsame unless $.max ~~ Numeric and $.min ~~ Numeric;
+ my $lo := $.min + $.excludes_min;
+ my $hi := $.max - $.excludes_max;
+ return 0 if $hi < $lo;
+ return ($hi - $lo + 1).floor;
+ }
}
--
1.7.1
|
From @moritzOn 01/16/2011 07:47 PM, Gilbert R. Roehrbein (via RT) wrote:
... and creates others. Consider (0..^3.3).Numeric Where you patch makes it return 3, but 4 is the correct answer. Maybe checking for ~~ Int instead of ~~ Numeric helps, but we also need Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
From payload@lavabit.comOn Mo, 2011-01-17 at 13:34 -0800, Moritz Lenz via RT wrote:
shame :( but fixed it ^^
does now work for following ranges for |
From payload@lavabit.comanother-fix.patchdiff --git a/src/core/Range.pm b/src/core/Range.pm
index fc1395b..baffe3f 100644
--- a/src/core/Range.pm
+++ b/src/core/Range.pm
@@ -103,6 +103,16 @@ class Range is Iterable does Positional {
multi method roll(Whatever) {
self.roll(Inf);
}
+
+ # to optimize the calculation of the size of a big range
+ # +(42..$big) doesnt take too much time now
+ multi method Numeric () {
+ nextsame unless $.max ~~ Numeric and $.min ~~ Numeric;
+ my $lo := $.min + $.excludes_min;
+ return 0 if $.max < $lo;
+ my $ret := ($.max - $lo + 1).floor;
+ return $ret - ($.excludes_max and $.max == $lo + $ret);
+ }
}
|
From @cokeOn Wed Jan 19 01:29:06 2011, payload wrote:
Sorry about the delay: Added tests to S02-types/range.t, and applied a heavily modified version of the patch (there $ time ./perl6 -e 'say +(123..123121231231231212321)' real 0m0.475s -- |
@coke - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#82312 (status was 'resolved')
Searchable as RT82312$
The text was updated successfully, but these errors were encountered: