]> arthur.barton.de Git - netdata.git/commitdiff
loop optimizations
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 6 Oct 2016 19:49:22 +0000 (22:49 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 6 Oct 2016 19:49:22 +0000 (22:49 +0300)
web/dashboard.js

index 4dd86391b871948bc308218de6805ecb26003bbd..7395088a2bd012332be1836aac67fe903fdc8c08 100644 (file)
         this.value_div = null;
         this.color = NETDATA.themes.current.foreground;
 
-        if(parent.selected_count > parent.unselected_count)
+        if(parent.unselected_count === 0)
             this.selected = true;
         else
             this.selected = false;
         this.selected_count = 0;
         this.unselected_count = 0;
 
-        for(var i = 0, len = array.length; i < len ; i++) {
-            var ds = this.dimensions[array[i]];
+        var len = array.length;
+        while(len--) {
+            var ds = this.dimensions[array[len]];
             if(typeof ds === 'undefined') {
                 // console.log(array[i] + ' is not found');
-                ret.push(false);
-                continue;
+                ret.unshift(false);
             }
-
-            if(ds.isSelected()) {
-                ret.push(true);
+            else if(ds.isSelected()) {
+                ret.unshift(true);
                 this.selected_count++;
             }
             else {
-                ret.push(false);
+                ret.unshift(false);
                 this.unselected_count++;
             }
         }
 
             if(typeof this.colors_assigned[label] === 'undefined') {
                 if(this.colors_available.length === 0) {
-                    for(var i = 0, len = NETDATA.themes.current.colors.length; i < len ; i++)
-                        this.colors_available.push(NETDATA.themes.current.colors[i]);
+                    var len = NETDATA.themes.current.colors.length;
+                    while(len--)
+                        this.colors_available.unshift(NETDATA.themes.current.colors[len]);
                 }
 
                 this.colors_assigned[label] = this.colors_available.shift();
                     var added = 0;
 
                     while(added < 20) {
-                        for(i = 0, len = c.length; i < len ; i++) {
+                        len = c.length;
+                        while(len--) {
                             added++;
-                            this.colors_available.push(c[i]);
+                            this.colors_available.unshift(c[len]);
                             // this.log('adding color: ' + c[i]);
                         }
                     }
             }
 
             // push all the standard colors too
-            for(i = 0, len = NETDATA.themes.current.colors.length; i < len ; i++)
-                this.colors_available.push(NETDATA.themes.current.colors[i]);
+            len = NETDATA.themes.current.colors.length;
+            while(len--)
+                this.colors_available.unshift(NETDATA.themes.current.colors[len]);
 
             return this.colors;
         };