proxmox-rrd: avoid expensive modulo (%) inside loop

Modulo is very slow, so we try to avoid it inside loops.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-10-13 10:24:48 +02:00 committed by Thomas Lamprecht
parent ec08247e5c
commit 5885767b91
1 changed files with 4 additions and 4 deletions

View File

@ -153,8 +153,7 @@ impl RRA {
if let Some(v) = data[i] {
self.data[index] = v;
}
index += 1;
if index >= self.data.len() { index = 0; }
index += 1; if index >= self.data.len() { index = 0; }
}
Ok(())
}
@ -171,7 +170,7 @@ impl RRA {
let mut index = ((t/reso) % num_entries) as usize;
for _ in 0..num_entries {
t += reso;
index = (index + 1) % (num_entries as usize);
index += 1; if index >= self.data.len() { index = 0; }
if t < min_time {
self.data[index] = f64::NAN;
} else {
@ -251,7 +250,8 @@ impl RRA {
list.push(Some(value));
}
}
t += reso; index = (index + 1) % (num_entries as usize);
t += reso;
index += 1; if index >= self.data.len() { index = 0; }
}
(start, reso, list)