Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/watcher.js

Issue 29332787: Issue 3420 - Get rid of for each loops in Diagnostics (Closed)
Patch Set: Created Dec. 16, 2015, 11:20 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 const Cc = Components.classes; 7 const Cc = Components.classes;
8 const Ci = Components.interfaces; 8 const Ci = Components.interfaces;
9 const Cr = Components.results; 9 const Cr = Components.results;
10 const Cu = Components.utils; 10 const Cu = Components.utils;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return; 97 return;
98 98
99 function stringify(value) 99 function stringify(value)
100 { 100 {
101 if (typeof value == "undefined" || value == null) 101 if (typeof value == "undefined" || value == null)
102 return ""; 102 return "";
103 else 103 else
104 return String(value); 104 return String(value);
105 } 105 }
106 106
107 for each (let entry in processingQueue) 107 for (let entry of processingQueue)
108 { 108 {
109 entry.cols = { 109 entry.cols = {
110 address: stringify(entry.location), 110 address: stringify(entry.location),
111 type: stringify(entry.type), 111 type: stringify(entry.type),
112 result: stringBundle.GetStringFromName(entry.result && entry.result.allow ? "decision.allow" : "decision.block"), 112 result: stringBundle.GetStringFromName(entry.result && entry.result.allow ? "decision.allow" : "decision.block"),
113 origin: stringify(entry.frames && entry.frames[0] && entry.frames[0].locat ion), 113 origin: stringify(entry.frames && entry.frames[0] && entry.frames[0].locat ion),
114 private: stringBundle.GetStringFromName(entry.isPrivate ? "private.yes" : "private.no"), 114 private: stringBundle.GetStringFromName(entry.isPrivate ? "private.yes" : "private.no"),
115 filter: stringify(entry.filters && entry.filters.join(", ")), 115 filter: stringify(entry.filters && entry.filters.join(", ")),
116 time: stringify(entry.processingTime) 116 time: stringify(entry.processingTime)
117 }; 117 };
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
195 } 195 }
196 196
197 var totalProcessingTime = 0; 197 var totalProcessingTime = 0;
198 function updateProcessingTime(view, operation, entry) 198 function updateProcessingTime(view, operation, entry)
199 { 199 {
200 if (operation == "add") 200 if (operation == "add")
201 totalProcessingTime += entry.processingTime; 201 totalProcessingTime += entry.processingTime;
202 else { 202 else {
203 totalProcessingTime = 0; 203 totalProcessingTime = 0;
204 for each (let entry in view.displayedItems) 204 for (let entry of view.displayedItems)
205 totalProcessingTime += entry.processingTime; 205 totalProcessingTime += entry.processingTime;
206 } 206 }
207 207
208 let numItems = view.displayedItems.length; 208 let numItems = view.displayedItems.length;
209 209
210 let summary = document.getElementById("summary"); 210 let summary = document.getElementById("summary");
211 let template = summary.getAttribute("_template"); 211 let template = summary.getAttribute("_template");
212 summary.textContent = template.replace(/\*NUMITEMS\*/g, numItems).replace(/\*T IME\*/, (totalProcessingTime / 1000).toFixed(3)); 212 summary.textContent = template.replace(/\*NUMITEMS\*/g, numItems).replace(/\*T IME\*/, (totalProcessingTime / 1000).toFixed(3));
213 } 213 }
214 214
(...skipping 28 matching lines...) Expand all
243 selection: null, 243 selection: null,
244 244
245 setTree: function(boxObject) 245 setTree: function(boxObject)
246 { 246 {
247 if (!boxObject) 247 if (!boxObject)
248 return; 248 return;
249 249
250 this.boxObject = boxObject; 250 this.boxObject = boxObject;
251 251
252 let atomService = Cc["@mozilla.org/atom-service;1"].getService(Ci.nsIAtomSer vice); 252 let atomService = Cc["@mozilla.org/atom-service;1"].getService(Ci.nsIAtomSer vice);
253 for each (let col in ["address", "type", "result", "origin", "private", "fil ter", "time"]) 253 for (let col of ["address", "type", "result", "origin", "private", "filter", "time"])
254 { 254 {
255 let atomStr = "col-" + col; 255 let atomStr = "col-" + col;
256 this.atoms[atomStr] = atomService.getAtom(atomStr); 256 this.atoms[atomStr] = atomService.getAtom(atomStr);
257 } 257 }
258 for each (let flag in ["selected", "blocked"]) 258 for (let flag of ["selected", "blocked"])
259 { 259 {
260 let atomStr = flag + "-true"; 260 let atomStr = flag + "-true";
261 this.atoms[atomStr] = atomService.getAtom(atomStr); 261 this.atoms[atomStr] = atomService.getAtom(atomStr);
262 262
263 atomStr = flag + "-false"; 263 atomStr = flag + "-false";
264 this.atoms[atomStr] = atomService.getAtom(atomStr); 264 this.atoms[atomStr] = atomService.getAtom(atomStr);
265 } 265 }
266 266
267 // Check current sort direction 267 // Check current sort direction
268 let cols = document.getElementsByTagName("treecol"); 268 let cols = document.getElementsByTagName("treecol");
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 { 403 {
404 this._filterString = value.toLowerCase(); 404 this._filterString = value.toLowerCase();
405 this.refilter(); 405 this.refilter();
406 }, 406 },
407 407
408 filter: function(entry) 408 filter: function(entry)
409 { 409 {
410 if (this._filterString) 410 if (this._filterString)
411 { 411 {
412 let foundMatch = false; 412 let foundMatch = false;
413 for each (let label in entry.cols) 413 for (let label of entry.cols)
414 if (label.toLowerCase().indexOf(this._filterString) >= 0) 414 if (label.toLowerCase().indexOf(this._filterString) >= 0)
415 foundMatch = true; 415 foundMatch = true;
416 416
417 if (!foundMatch) 417 if (!foundMatch)
418 return false; 418 return false;
419 } 419 }
420 return true; 420 return true;
421 }, 421 },
422 422
423 compare: function(entry1, entry2) 423 compare: function(entry1, entry2)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 this.observers.push(observer); 525 this.observers.push(observer);
526 }, 526 },
527 removeObserver: function(observer) 527 removeObserver: function(observer)
528 { 528 {
529 for (let i = 0; i < this.observers.length; i++) 529 for (let i = 0; i < this.observers.length; i++)
530 if (this.observers[i] == observer) 530 if (this.observers[i] == observer)
531 this.observers.splice(i--, 1); 531 this.observers.splice(i--, 1);
532 }, 532 },
533 notifyObservers: function(operation, entry) 533 notifyObservers: function(operation, entry)
534 { 534 {
535 for each (let observer in this.observers) 535 for (let observer of this.observers)
536 observer(this, operation, entry); 536 observer(this, operation, entry);
537 } 537 }
538 }; 538 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld