diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-11-22 12:18:07 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-11-24 15:29:45 +0100 |
commit | 721057583db22c0087563066f32428b6d5f45805 (patch) | |
tree | 820daee0a6a659d1fdebc7c835e0edeadcbba006 | |
parent | 02939068e351ce5e37f5258c3ecb45480f3d3656 (diff) |
Optimize implementation
Change the implementation from O(n) to O(1).
-rw-r--r-- | src/util.rs | 8 |
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; } } |