Bug 1426525 part 2. Remove the now-nearly-unused XULDocument::GetElementsForID method. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 05 Jan 2018 13:48:39 -0500
changeset 449828 07e377e19c7d462a4dc2e674e0163a400b3a572d
parent 449827 c713ef0ecf0966e392acd6fe6d790c8844b70ec5
child 449829 c9fad2f644485a0508a00985ac27c16ef1013e80
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1426525
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1426525 part 2. Remove the now-nearly-unused XULDocument::GetElementsForID method. r=smaug MozReview-Commit-ID: Gv23I8gLhem
dom/base/nsDocument.cpp
dom/base/nsIdentifierMapEntry.h
dom/xul/XULDocument.cpp
dom/xul/XULDocument.h
dom/xul/nsIXULDocument.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -440,24 +440,16 @@ nsIdentifierMapEntry::GetIdElement()
 
 Element*
 nsIdentifierMapEntry::GetImageIdElement()
 {
   return mImageElement ? mImageElement.get() : GetIdElement();
 }
 
 void
-nsIdentifierMapEntry::AppendAllIdContent(nsCOMArray<Element>* aElements)
-{
-  for (Element* element : mIdContentList) {
-    aElements->AppendObject(element);
-  }
-}
-
-void
 nsIdentifierMapEntry::AddContentChangeCallback(nsIDocument::IDTargetObserver aCallback,
                                                void* aData, bool aForImage)
 {
   if (!mChangeCallbacks) {
     mChangeCallbacks = new nsTHashtable<ChangeCallbackEntry>;
   }
 
   ChangeCallback cc = { aCallback, aData, aForImage };
--- a/dom/base/nsIdentifierMapEntry.h
+++ b/dom/base/nsIdentifierMapEntry.h
@@ -12,17 +12,16 @@
 #define nsIdentifierMapEntry_h
 
 #include "PLDHashTable.h"
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
-#include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsAtom.h"
 #include "nsTArray.h"
 #include "nsTHashtable.h"
 
 class nsIContent;
 class nsContentList;
 class nsBaseContentList;
@@ -135,20 +134,16 @@ public:
     return mIdContentList;
   }
   /**
    * If this entry has a non-null image element set (using SetImageElement),
    * the image element will be returned, otherwise the same as GetIdElement().
    */
   Element* GetImageIdElement();
   /**
-   * Append all the elements with this id to aElements
-   */
-  void AppendAllIdContent(nsCOMArray<Element>* aElements);
-  /**
    * This can fire ID change callbacks.
    * @return true if the content could be added, false if we failed due
    * to OOM.
    */
   bool AddIdElement(Element* aElement);
   /**
    * This can fire ID change callbacks.
    */
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1016,28 +1016,16 @@ XULDocument::ContentRemoved(nsIDocument*
     RemoveSubtreeFromDocument(aChild);
 }
 
 //----------------------------------------------------------------------
 //
 // nsIXULDocument interface
 //
 
-void
-XULDocument::GetElementsForID(const nsAString& aID,
-                              nsCOMArray<Element>& aElements)
-{
-    aElements.Clear();
-
-    nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(aID);
-    if (entry) {
-        entry->AppendAllIdContent(&aElements);
-    }
-}
-
 nsresult
 XULDocument::AddForwardReference(nsForwardReference* aRef)
 {
     if (mResolutionPhase < aRef->GetPhase()) {
         if (!mForwardReferences.AppendElement(aRef)) {
             delete aRef;
             return NS_ERROR_OUT_OF_MEMORY;
         }
@@ -1888,19 +1876,29 @@ XULDocument::ApplyPersistentAttributesIn
 
         nsAutoString id;
         ids->GetNext(id);
 
         if (mRestrictPersistence && !mPersistenceIds.Contains(id)) {
             continue;
         }
 
-        // This will clear the array if there are no elements.
-        GetElementsForID(id, elements);
-        if (!elements.Count()) {
+        nsIdentifierMapEntry* entry = mIdentifierMap.GetEntry(id);
+        if (!entry) {
+            continue;
+        }
+
+        // We want to hold strong refs to the elements while applying
+        // persistent attributes, just in case.
+        elements.Clear();
+        elements.SetCapacity(entry->GetIdElements().Length());
+        for (Element* element : entry->GetIdElements()) {
+            elements.AppendObject(element);
+        }
+        if (elements.IsEmpty()) {
             continue;
         }
 
         rv = ApplyPersistentAttributesToElements(id, elements);
         if (NS_WARN_IF(NS_FAILED(rv))) {
             return rv;
         }
     }
--- a/dom/xul/XULDocument.h
+++ b/dom/xul/XULDocument.h
@@ -86,19 +86,16 @@ public:
 
     // nsIMutationObserver interface
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
 
     // nsIXULDocument interface
-    virtual void GetElementsForID(const nsAString& aID,
-                                  nsCOMArray<mozilla::dom::Element>& aElements) override;
-
     NS_IMETHOD AddSubtreeToDocument(nsIContent* aContent) override;
     NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aContent) override;
     NS_IMETHOD OnPrototypeLoadDone(bool aResumeWalk) override;
     bool OnDocumentParserError() override;
 
     // nsINode interface overrides
     virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                            bool aPreallocateChildren) const override;
--- a/dom/xul/nsIXULDocument.h
+++ b/dom/xul/nsIXULDocument.h
@@ -31,24 +31,16 @@ class Element;
  * method for constructing the children of a node, etc.
  */
 class nsIXULDocument : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXULDOCUMENT_IID)
 
   /**
-   * Get the elements for a particular resource --- all elements whose 'id'
-   * or 'ref' is aID. The nsCOMArray will be truncated and filled in with
-   * nsIContent pointers.
-   */
-  virtual void GetElementsForID(const nsAString& aID,
-                                nsCOMArray<mozilla::dom::Element>& aElements) = 0;
-
-  /**
    * Notify the XUL document that a subtree has been added
    */
   NS_IMETHOD AddSubtreeToDocument(nsIContent* aElement) = 0;
 
   /**
    * Notify the XUL document that a subtree has been removed
    */
   NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aElement) = 0;