From 5a2e6baba3c8a9d695efb629b40f4634ec1eb40e Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Fri, 25 Jan 2008 00:23:10 -0800 Subject: [PATCH] Bug 412600 - "for each over Arrays considered harmful" [p=tjduavis@gmail.com (Timothy Joseph Duavis) r=dietrich a1.9=beltzner] --- .../places/content/editBookmarkOverlay.js | 17 +++++++++-------- browser/components/places/content/treeView.js | 6 ++++-- browser/components/places/content/utils.js | 6 ++++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/browser/components/places/content/editBookmarkOverlay.js b/browser/components/places/content/editBookmarkOverlay.js index d96b459ba9f..63fc862a0bb 100644 --- a/browser/components/places/content/editBookmarkOverlay.js +++ b/browser/components/places/content/editBookmarkOverlay.js @@ -438,14 +438,14 @@ var gEditItemOverlay = { if (tags.length > 0 || currentTags.length > 0) { var tagsToRemove = []; var tagsToAdd = []; - var t; - for each (t in currentTags) { - if (tags.indexOf(t) == -1) - tagsToRemove.push(t); + var i; + for (i = 0; i < currentTags.length; i++) { + if (tags.indexOf(currentTags[i]) == -1) + tagsToRemove.push(currentTags[i]); } - for each (t in tags) { - if (currentTags.indexOf(t) == -1) - tagsToAdd.push(t); + for (i = 0; i < tags.length; i++) { + if (currentTags.indexOf(tags[i]) == -1) + tagsToAdd.push(tags[i]); } if (tagsToAdd.length > 0) @@ -682,7 +682,8 @@ var gEditItemOverlay = { var tagsInField = this._getTagsArrayFromTagField(); var allTags = PlacesUtils.tagging.allTags; - for each (var tag in allTags) { + for (var i = 0; i < allTags.length; i++) { + var tag = allTags[i]; var elt = document.createElement("listitem"); elt.setAttribute("type", "checkbox"); elt.setAttribute("label", tag); diff --git a/browser/components/places/content/treeView.js b/browser/components/places/content/treeView.js index 3acaf9e5940..d958f201ab6 100644 --- a/browser/components/places/content/treeView.js +++ b/browser/components/places/content/treeView.js @@ -375,7 +375,8 @@ PlacesTreeView.prototype = { // restore selection if (previouslySelectedNodes.length > 0) { - for each (var nodeInfo in previouslySelectedNodes) { + for (var i = 0; i < previouslySelectedNodes.length; i++) { + var nodeInfo = previouslySelectedNodes[i]; var index = nodeInfo.node.viewIndex; // if the same node was used (happens on sorting-changes), @@ -780,7 +781,8 @@ PlacesTreeView.prototype = { // restore selection if (nodesToSelect.length > 0) { - for each (var node in nodesToSelect) { + for (var i = 0; i < nodesToSelect.length; i++) { + var node = nodesToSelect[i]; var index = node.viewIndex; selection.rangedSelect(index, index, true); } diff --git a/browser/components/places/content/utils.js b/browser/components/places/content/utils.js index 0e2dddeb45b..c6b80893978 100644 --- a/browser/components/places/content/utils.js +++ b/browser/components/places/content/utils.js @@ -1566,8 +1566,9 @@ var PlacesUtils = { getMostRecentBookmarkForURI: function PU_getMostRecentBookmarkForURI(aURI) { var bmkIds = this.bookmarks.getBookmarkIdsForURI(aURI, {}); - for each (var bk in bmkIds) { + for (var i = 0; i < bmkIds.length; i++) { // Find the first folder which isn't a tag container + var bk = bmkIds[i]; var parent = this.bookmarks.getFolderIdForItem(bk); if (parent == this.unfiledBookmarksFolderId) return bk; @@ -1688,7 +1689,8 @@ var PlacesUtils = { */ _openTabset: function PU__openTabset(aItemsToOpen, aEvent) { var urls = []; - for each (var item in aItemsToOpen) { + for (var i = 0; i < aItemsToOpen.length; i++) { + var item = aItemsToOpen[i]; if (item.isBookmark) this.markPageAsFollowedBookmark(item.uri); else