summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-11-22 12:18:07 +0100
committerMatthias Beyer <mail@beyermatthias.de>2017-11-24 15:29:45 +0100
commit721057583db22c0087563066f32428b6d5f45805 (patch)
tree820daee0a6a659d1fdebc7c835e0edeadcbba006
parent02939068e351ce5e37f5258c3ecb45480f3d3656 (diff)
Optimize implementation
Change the implementation from O(n) to O(1).
-rw-r--r--src/util.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/util.rs b/src/util.rs
index 7730b2b..1ed9a7a 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -2,16 +2,16 @@
pub fn adjust_times_add(mut y: i64, mut mo: i64, mut d: i64, mut h: i64, mut mi: i64, mut s: i64)
-> (i64, i64, i64, i64, i64, i64)
{
+ // Subtract $border from the $base as long as the $base is bigger or equal to the $border.
+ // The number of subtractions are added to $next.
macro_rules! fix {
{
$base:ident,
$border:expr,
$next:ident
} => {
- while $base >= $border {
- $next += 1;
- $base -= $border;
- }
+ $next += ($base - ($base % $border)) / $border;
+ $base = $base % $border;
}
}