From 334eb9ce48c20b836c6ac6c7b3fb78493798091b Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 13 Oct 2021 10:24:48 +0200 Subject: [PATCH] proxmox-rrd: avoid expensive modulo (%) inside loop Modulo is very slow, so we try to avoid it inside loops. Signed-off-by: Dietmar Maurer Signed-off-by: Thomas Lamprecht --- proxmox-rrd/src/rrd.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proxmox-rrd/src/rrd.rs b/proxmox-rrd/src/rrd.rs index 7a9ce94a..54cb8b48 100644 --- a/proxmox-rrd/src/rrd.rs +++ b/proxmox-rrd/src/rrd.rs @@ -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)