From fed270bf3f92b395d425d080ef753881d3a9c03d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 16 May 2020 07:09:53 +0200 Subject: [PATCH] CalendarEvent: speedup/simplify repetition tests --- src/tools/systemd/time.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/tools/systemd/time.rs b/src/tools/systemd/time.rs index 0de98a33..42d0062d 100644 --- a/src/tools/systemd/time.rs +++ b/src/tools/systemd/time.rs @@ -32,17 +32,15 @@ impl DateTimeValue { DateTimeValue::Single(v) => *v == value, DateTimeValue::Range(start, end) => value >= *start && value <= *end, DateTimeValue::Repeated(start, repetition) => { - if *repetition > 0 { - let mut found = false; - let mut v = *start; - loop { - if v == value { found = true; break; } - v += *repetition; - if v > value { break; } + if value >= *start { + if *repetition > 0 { + let offset = value - start; + offset % repetition == 0 + } else { + *start == value } - found } else { - *start == value + false } } } @@ -77,12 +75,7 @@ impl DateTimeValue { if value < *start { set_next(*start); } else if *repetition > 0 { - let mut v = *start; - loop { - if v > value { set_next(v); break; } - v += *repetition; - if v > value { break; } - } + set_next(((value - start + repetition) / repetition) * repetition); } } }