loop optimizations
Costa Tsaousis (ktsaou) committed
Oct 6, 2016 at 22:49 UTC
359033f0f970692ceb57ffaa7c66faf01e12327f
1 file changed
+17
-15
web/dashboard.js
+17
-15
@@ -836,7 +836,7 @@
836
this.value_div = null;
837
this.color = NETDATA.themes.current.foreground;
838
839
- if(parent.selected_count > parent.unselected_count)
839
+ if(parent.unselected_count === 0)
840
this.selected = true;
841
else
842
this.selected = false;
@@ -995,20 +995,19 @@
995
this.selected_count = 0;
996
this.unselected_count = 0;
997
998
- for(var i = 0, len = array.length; i < len ; i++) {
999
- var ds = this.dimensions[array[i]];
998
+ var len = array.length;
999
+ while(len--) {
1000
+ var ds = this.dimensions[array[len]];
1001
if(typeof ds === 'undefined') {
1002
// console.log(array[i] + ' is not found');
1002
- ret.push(false);
1003
- continue;
1003
+ ret.unshift(false);
1004
}
1005
-
1006
- if(ds.isSelected()) {
1007
- ret.push(true);
1005
+ else if(ds.isSelected()) {
1006
+ ret.unshift(true);
1007
this.selected_count++;
1008
}
1009
else {
1011
- ret.push(false);
1010
+ ret.unshift(false);
1011
this.unselected_count++;
1012
}
1013
}
@@ -2177,8 +2176,9 @@
2176
2177
if(typeof this.colors_assigned[label] === 'undefined') {
2178
if(this.colors_available.length === 0) {
2180
- for(var i = 0, len = NETDATA.themes.current.colors.length; i < len ; i++)
2181
- this.colors_available.push(NETDATA.themes.current.colors[i]);
2179
+ var len = NETDATA.themes.current.colors.length;
2180
+ while(len--)
2181
+ this.colors_available.unshift(NETDATA.themes.current.colors[len]);
2182
}
2183
2184
this.colors_assigned[label] = this.colors_available.shift();
@@ -2213,9 +2213,10 @@
2213
var added = 0;
2214
2215
while(added < 20) {
2216
- for(i = 0, len = c.length; i < len ; i++) {
2216
+ len = c.length;
2217
+ while(len--) {
2218
added++;
2218
- this.colors_available.push(c[i]);
2219
+ this.colors_available.unshift(c[len]);
2220
// this.log('adding color: ' + c[i]);
2221
}
2222
}
@@ -2223,8 +2224,9 @@
2224
}
2225
2226
// push all the standard colors too
2226
- for(i = 0, len = NETDATA.themes.current.colors.length; i < len ; i++)
2227
- this.colors_available.push(NETDATA.themes.current.colors[i]);
2227
+ len = NETDATA.themes.current.colors.length;
2228
+ while(len--)
2229
+ this.colors_available.unshift(NETDATA.themes.current.colors[len]);
2230
2231
return this.colors;
2232
};