From 721057583db22c0087563066f32428b6d5f45805 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 22 Nov 2017 12:18:07 +0100 Subject: Optimize implementation Change the implementation from O(n) to O(1). --- src/util.rs | 8 ++++---- 1 file 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; } } -- cgit v1.2.3