tools/systemd/tm_editor: remove TMChanges optimization

while it was correct, there was no measurable speed gain
(a benchmark yielded 2.8 ms for a spec that did not find a timestamp either way)
so remove it for simpler code

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2020-09-04 14:33:24 +02:00
committed by Dietmar Maurer
parent 56b666458c
commit 28a0a9343c
2 changed files with 9 additions and 48 deletions

View File

@ -172,12 +172,10 @@ pub fn compute_next_event(
count += 1;
}
if !all_days && t.changes.contains(TMChanges::WDAY) { // match day first
if !all_days { // match day first
let day_num = t.day_num();
let day = WeekDays::from_bits(1<<day_num).unwrap();
if event.days.contains(day) {
t.changes.remove(TMChanges::WDAY);
} else {
if !event.days.contains(day) {
if let Some(n) = ((day_num+1)..7)
.find(|d| event.days.contains(WeekDays::from_bits(1<<d).unwrap()))
{
@ -193,11 +191,9 @@ pub fn compute_next_event(
}
// this day
if !event.hour.is_empty() && t.changes.contains(TMChanges::HOUR) {
if !event.hour.is_empty() {
let hour = t.hour() as u32;
if DateTimeValue::list_contains(&event.hour, hour) {
t.changes.remove(TMChanges::HOUR);
} else {
if !DateTimeValue::list_contains(&event.hour, hour) {
if let Some(n) = DateTimeValue::find_next(&event.hour, hour) {
// test next hour
t.set_time(n as libc::c_int, 0, 0);
@ -211,11 +207,9 @@ pub fn compute_next_event(
}
// this hour
if !event.minute.is_empty() && t.changes.contains(TMChanges::MIN) {
if !event.minute.is_empty() {
let minute = t.min() as u32;
if DateTimeValue::list_contains(&event.minute, minute) {
t.changes.remove(TMChanges::MIN);
} else {
if !DateTimeValue::list_contains(&event.minute, minute) {
if let Some(n) = DateTimeValue::find_next(&event.minute, minute) {
// test next minute
t.set_min_sec(n as libc::c_int, 0);
@ -229,11 +223,9 @@ pub fn compute_next_event(
}
// this minute
if !event.second.is_empty() && t.changes.contains(TMChanges::SEC) {
if !event.second.is_empty() {
let second = t.sec() as u32;
if DateTimeValue::list_contains(&event.second, second) {
t.changes.remove(TMChanges::SEC);
} else {
if !DateTimeValue::list_contains(&event.second, second) {
if let Some(n) = DateTimeValue::find_next(&event.second, second) {
// test next second
t.set_sec(n as libc::c_int);