Bug 718504 - Remove some GetChildAt callers; r=smaug
authorMs2ger <ms2ger@gmail.com>
Wed, 25 Jan 2012 08:50:07 +0100
changeset 87653 005488525c43e46e1ada6da5d4df8621818577ce
parent 87652 70991ab26e20de36cbdcab9fc8a1d29113101e0d
child 87654 69d3ab27a237176169e328f52437417a4edc2e31
child 87773 93e51ab759cbbb189ef9b89a0af3b46262eec1f1
push id674
push userffxbld
push dateTue, 13 Mar 2012 21:17:50 +0000
treeherdermozilla-beta@e3c4c92dec31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs718504
milestone12.0a1
first release with
nightly linux32
005488525c43 / 12.0a1 / 20120125031119 / files
nightly linux64
005488525c43 / 12.0a1 / 20120125031119 / files
nightly mac
005488525c43 / 12.0a1 / 20120125031119 / files
nightly win32
005488525c43 / 12.0a1 / 20120125031119 / files
nightly win64
005488525c43 / 12.0a1 / 20120125031119 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 718504 - Remove some GetChildAt callers; r=smaug
accessible/src/html/nsHTMLTableAccessible.cpp
content/base/public/nsINode.h
dom/base/nsFocusManager.cpp
layout/printing/nsPrintEngine.cpp
layout/xul/base/src/nsXULPopupManager.cpp
parser/html/nsHtml5TreeOperation.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
widget/windows/nsNativeThemeWin.cpp
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -1340,17 +1340,17 @@ nsHTMLTableAccessible::HasDescendant(con
     return true;
 
   // Make sure that the item we found has contents and either has multiple
   // children or the found item is not a whitespace-only text node.
   nsCOMPtr<nsIContent> foundItemContent = do_QueryInterface(foundItem);
   if (foundItemContent->GetChildCount() > 1)
     return true; // Treat multiple child nodes as non-empty
 
-  nsIContent *innerItemContent = foundItemContent->GetChildAt(0);
+  nsIContent *innerItemContent = foundItemContent->GetFirstChild();
   if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
     return true;
 
   // If we found more than one node then return true not depending on
   // aAllowEmpty flag.
   // XXX it might be dummy but bug 501375 where we changed this addresses
   // performance problems only. Note, currently 'aAllowEmpty' flag is used for
   // caption element only. On another hand we create accessible object for
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -374,16 +374,21 @@ public:
 
   /**
    * Return this node as an Element.  Should only be used for nodes
    * for which IsElement() is true.
    */
   mozilla::dom::Element* AsElement();
 
   /**
+   * Return if this node has any children.
+   */
+  bool HasChildren() const { return !!mFirstChild; }
+
+  /**
    * Get the number of children
    * @return the number of children
    */
   virtual PRUint32 GetChildCount() const = 0;
 
   /**
    * Get a child by index
    * @param aIndex the index of the child to get
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -2911,41 +2911,40 @@ nsFocusManager::GetNextTabbableMapArea(b
 }
 
 PRInt32
 nsFocusManager::GetNextTabIndex(nsIContent* aParent,
                                 PRInt32 aCurrentTabIndex,
                                 bool aForward)
 {
   PRInt32 tabIndex, childTabIndex;
-  nsIContent *child;
-
-  PRUint32 count = aParent->GetChildCount();
 
   if (aForward) {
     tabIndex = 0;
-    for (PRUint32 index = 0; index < count; index++) {
-      child = aParent->GetChildAt(index);
+    for (nsIContent* child = aParent->GetFirstChild();
+         child;
+         child = child->GetNextSibling()) {
       childTabIndex = GetNextTabIndex(child, aCurrentTabIndex, aForward);
       if (childTabIndex > aCurrentTabIndex && childTabIndex != tabIndex) {
         tabIndex = (tabIndex == 0 || childTabIndex < tabIndex) ? childTabIndex : tabIndex;
       }
 
       nsAutoString tabIndexStr;
       child->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndexStr);
       PRInt32 ec, val = tabIndexStr.ToInteger(&ec);
       if (NS_SUCCEEDED (ec) && val > aCurrentTabIndex && val != tabIndex) {
         tabIndex = (tabIndex == 0 || val < tabIndex) ? val : tabIndex;
       }
     }
   }
   else { /* !aForward */
     tabIndex = 1;
-    for (PRUint32 index = 0; index < count; index++) {
-      child = aParent->GetChildAt(index);
+    for (nsIContent* child = aParent->GetFirstChild();
+         child;
+         child = child->GetNextSibling()) {
       childTabIndex = GetNextTabIndex(child, aCurrentTabIndex, aForward);
       if ((aCurrentTabIndex == 0 && childTabIndex > tabIndex) ||
           (childTabIndex < aCurrentTabIndex && childTabIndex > tabIndex)) {
         tabIndex = childTabIndex;
       }
 
       nsAutoString tabIndexStr;
       child->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndexStr);
@@ -2991,33 +2990,28 @@ nsFocusManager::GetRootForFocus(nsPIDOMW
     if (itemType == nsIDocShellTreeItem::typeChrome)
       return nsnull;
   }
 
   if (aCheckVisibility && !IsWindowVisible(aWindow))
     return nsnull;
 
   Element *rootElement = aDocument->GetRootElement();
-  if (rootElement) {
-    if (aCheckVisibility && !rootElement->GetPrimaryFrame()) {
-      return nsnull;
-    }
-
-    // Finally, check if this is a frameset
-    nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(aDocument);
-    if (htmlDoc) {
-      PRUint32 childCount = rootElement->GetChildCount();
-      for (PRUint32 i = 0; i < childCount; ++i) {
-        nsIContent *childContent = rootElement->GetChildAt(i);
-        nsINodeInfo *ni = childContent->NodeInfo();
-        if (childContent->IsHTML() &&
-            ni->Equals(nsGkAtoms::frameset))
-          return nsnull;
-      }
-    }
+  if (!rootElement) {
+    return nsnull;
+  }
+
+  if (aCheckVisibility && !rootElement->GetPrimaryFrame()) {
+    return nsnull;
+  }
+
+  // Finally, check if this is a frameset
+  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(aDocument);
+  if (htmlDoc && aDocument->GetHtmlChildElement(nsGkAtoms::frameset)) {
+    return nsnull;
   }
 
   return rootElement;
 }
 
 TabParent*
 nsFocusManager::GetRemoteForContent(nsIContent* aContent) {
   if (!aContent ||
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -1350,19 +1350,19 @@ nsPrintEngine::MapContentForPO(nsPrintOb
           NS_ASSERTION(po->mParent, "The root must be a parent");
           po->mParent->mPrintAsIs = true;
         }
       }
     }
   }
 
   // walk children content
-  PRUint32 count = aContent->GetChildCount();
-  for (PRUint32 i = 0; i < count; ++i) {
-    nsIContent *child = aContent->GetChildAt(i);
+  for (nsIContent* child = aContent->GetFirstChild();
+       child;
+       child = child->GetNextSibling()) {
     MapContentForPO(aPO, child);
   }
 }
 
 //---------------------------------------------------------------------
 bool
 nsPrintEngine::IsThereAnIFrameSelected(nsIDocShell* aDocShell,
                                        nsIDOMWindow* aDOMWin,
@@ -2758,23 +2758,21 @@ nsPrintEngine::CleanupDocTitleArray(PRUn
 //---------------------------------------------------------------------
 // static
 bool nsPrintEngine::HasFramesetChild(nsIContent* aContent)
 {
   if (!aContent) {
     return false;
   }
 
-  PRUint32 numChildren = aContent->GetChildCount();
-
   // do a breadth search across all siblings
-  for (PRUint32 i = 0; i < numChildren; ++i) {
-    nsIContent *child = aContent->GetChildAt(i);
-    if (child->Tag() == nsGkAtoms::frameset &&
-        child->IsHTML()) {
+  for (nsIContent* child = aContent->GetFirstChild();
+       child;
+       child = child->GetNextSibling()) {
+    if (child->IsHTML(nsGkAtoms::frameset)) {
       return true;
     }
   }
 
   return false;
 }
  
 
--- a/layout/xul/base/src/nsXULPopupManager.cpp
+++ b/layout/xul/base/src/nsXULPopupManager.cpp
@@ -1666,20 +1666,19 @@ nsXULPopupManager::UpdateKeyboardListene
 
 void
 nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup)
 {
   // Walk all of the menu's children, checking to see if any of them has a
   // command attribute. If so, then several attributes must potentially be updated.
  
   nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aPopup->GetDocument()));
-  PRUint32 count = aPopup->GetChildCount();
-  for (PRUint32 i = 0; i < count; i++) {
-    nsCOMPtr<nsIContent> grandChild = aPopup->GetChildAt(i);
-
+  for (nsCOMPtr<nsIContent> grandChild = aPopup->GetFirstChild();
+       grandChild;
+       grandChild = grandChild->GetNextSibling()) {
     if (grandChild->NodeInfo()->Equals(nsGkAtoms::menuitem, kNameSpaceID_XUL)) {
       // See if we have a command attribute.
       nsAutoString command;
       grandChild->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
       if (!command.IsEmpty()) {
         // We do! Look it up in our document
         nsCOMPtr<nsIDOMElement> commandElt;
         domDoc->GetElementById(command, getter_AddRefs(commandElt));
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -284,18 +284,18 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
       nsIContent* parent = *(mTwo.node);
       aBuilder->FlushPendingAppendNotifications();
 
       nsHtml5OtherDocUpdate update(parent->OwnerDoc(),
                                    aBuilder->GetDocument());
 
       PRUint32 childCount = parent->GetChildCount();
       bool didAppend = false;
-      while (node->GetChildCount()) {
-        nsCOMPtr<nsIContent> child = node->GetChildAt(0);
+      while (node->HasChildren()) {
+        nsCOMPtr<nsIContent> child = node->GetFirstChild();
         rv = node->RemoveChildAt(0, true);
         NS_ENSURE_SUCCESS(rv, rv);
         rv = parent->AppendChildTo(child, false);
         NS_ENSURE_SUCCESS(rv, rv);
         didAppend = true;
       }
       if (didAppend) {
         nsNodeUtils::ContentAppended(parent, parent->GetChildAt(childCount),
@@ -512,18 +512,18 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
 
       if (foster && foster->IsElement()) {
         aBuilder->FlushPendingAppendNotifications();
 
         nsHtml5OtherDocUpdate update(foster->OwnerDoc(),
                                      aBuilder->GetDocument());
 
         PRUint32 pos = foster->IndexOf(table);
-        
-        nsIContent* previousSibling = foster->GetChildAt(pos - 1);
+
+        nsIContent* previousSibling = table->GetPreviousSibling();
         if (previousSibling && previousSibling->IsNodeOfType(nsINode::eTEXT)) {
           return AppendTextToTextNode(buffer, 
                                       length, 
                                       previousSibling, 
                                       aBuilder);
         }
         
         nsCOMPtr<nsIContent> text;
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -850,21 +850,21 @@ nsTypeAheadFind::RangeStartsInsideLink(n
       }
     }
 
     // Get the parent
     nsCOMPtr<nsIContent> parent = startContent->GetParent();
     if (!parent)
       break;
 
-    nsIContent *parentsFirstChild = parent->GetChildAt(0);
+    nsIContent* parentsFirstChild = parent->GetFirstChild();
 
     // We don't want to look at a whitespace-only first child
     if (parentsFirstChild && parentsFirstChild->TextIsOnlyWhitespace()) {
-      parentsFirstChild = parent->GetChildAt(1);
+      parentsFirstChild = parentsFirstChild->GetNextSibling();
     }
 
     if (parentsFirstChild != startContent) {
       // startContent wasn't a first child, so we conclude that
       // if this is inside a link, it's not at the beginning of it
       *aIsStartingLink = false;
     }
 
--- a/widget/windows/nsNativeThemeWin.cpp
+++ b/widget/windows/nsNativeThemeWin.cpp
@@ -879,17 +879,17 @@ nsNativeThemeWin::GetThemePartAndState(n
       // for this item. We will pass any nessessary information via aState,
       // and will render the item using separate code.
       aPart = -1;
       aState = 0;
       if (aFrame) {
         nsIContent* content = aFrame->GetContent();
         nsIContent* parent = content->GetParent();
         // XXXzeniko hiding the first toolbar will result in an unwanted margin
-        if (parent && parent->GetChildAt(0) == content) {
+        if (parent && parent->GetFirstChild() == content) {
           aState = 1;
         }
       }
       return NS_OK;
     }
     case NS_THEME_STATUSBAR_PANEL:
     case NS_THEME_STATUSBAR_RESIZER_PANEL:
     case NS_THEME_RESIZER: {