]> git.proxmox.com Git - proxmox-backup.git/commitdiff
proxmox-rrd: avoid expensive modulo (%) inside loop
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 13 Oct 2021 08:24:48 +0000 (10:24 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 13 Oct 2021 11:36:02 +0000 (13:36 +0200)
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>
proxmox-rrd/src/rrd.rs

index 7a9ce94ae8d37dfe4c3ea516481bc35cee1f036d..54cb8b482fcbeed8e55ce867ead7981082edf0a5 100644 (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)