Bug 1444580: Devirtualize the IdentifierMap stuff. r=smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 10 Mar 2018 06:27:25 +0100
changeset 765766 477cc5476f6cf560dd40dbb934e7b4d06c8752a5
parent 765765 e6530b7c09b13f2cec850d331c04149201806292
push id102160
push userbmo:emilio@crisal.io
push dateSat, 10 Mar 2018 06:32:21 +0000
reviewerssmaug
bugs1444580
milestone60.0a1
Bug 1444580: Devirtualize the IdentifierMap stuff. r=smaug MozReview-Commit-ID: 5IIp95VEtvk
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -3135,17 +3135,17 @@ nsIDocument::GetLastModified(nsAString& 
   if (!mLastModified.IsEmpty()) {
     aLastModified.Assign(mLastModified);
   } else {
     GetFormattedTimeString(PR_Now(), aLastModified);
   }
 }
 
 void
-nsDocument::AddToNameTable(Element *aElement, nsAtom* aName)
+nsIDocument::AddToNameTable(Element* aElement, nsAtom* aName)
 {
   MOZ_ASSERT(nsGenericHTMLElement::ShouldExposeNameAsHTMLDocumentProperty(aElement),
              "Only put elements that need to be exposed as document['name'] in "
              "the named table.");
 
   nsIdentifierMapEntry* entry = mIdentifierMap.PutEntry(aName);
 
   // Null for out-of-memory
@@ -3154,17 +3154,17 @@ nsDocument::AddToNameTable(Element *aEle
         !entry->HasIdElementExposedAsHTMLDocumentProperty()) {
       ++mExpandoAndGeneration.generation;
     }
     entry->AddNameElement(this, aElement);
   }
 }
 
 void
-nsDocument::RemoveFromNameTable(Element *aElement, nsAtom* aName)
+nsIDocument::RemoveFromNameTable(Element* aElement, nsAtom* aName)
 {
   // Speed up document teardown
   if (mIdentifierMap.Count() == 0)
     return;
 
   nsIdentifierMapEntry* entry = mIdentifierMap.GetEntry(aName);
   if (!entry) // Could be false if the element was anonymous, hence never added
     return;
@@ -3172,32 +3172,32 @@ nsDocument::RemoveFromNameTable(Element 
   entry->RemoveNameElement(aElement);
   if (!entry->HasNameElement() &&
       !entry->HasIdElementExposedAsHTMLDocumentProperty()) {
     ++mExpandoAndGeneration.generation;
   }
 }
 
 void
-nsDocument::AddToIdTable(Element *aElement, nsAtom* aId)
+nsIDocument::AddToIdTable(Element* aElement, nsAtom* aId)
 {
   nsIdentifierMapEntry* entry = mIdentifierMap.PutEntry(aId);
 
   if (entry) { /* True except on OOM */
     if (nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(aElement) &&
         !entry->HasNameElement() &&
         !entry->HasIdElementExposedAsHTMLDocumentProperty()) {
       ++mExpandoAndGeneration.generation;
     }
     entry->AddIdElement(aElement);
   }
 }
 
 void
-nsDocument::RemoveFromIdTable(Element *aElement, nsAtom* aId)
+nsIDocument::RemoveFromIdTable(Element* aElement, nsAtom* aId)
 {
   NS_ASSERTION(aId, "huhwhatnow?");
 
   // Speed up document teardown
   if (mIdentifierMap.Count() == 0) {
     return;
   }
 
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -60,17 +60,16 @@
 #include "mozilla/PendingAnimationTracker.h"
 #include "mozilla/dom/BoxObject.h"
 #include "mozilla/dom/DOMImplementation.h"
 #include "mozilla/dom/ScriptLoader.h"
 #include "mozilla/dom/StyleSheetList.h"
 #include "nsDataHashtable.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Attributes.h"
-#include "jsfriendapi.h"
 #include "mozilla/LinkedList.h"
 #include "CustomElementRegistry.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/Maybe.h"
 #include "nsIURIClassifier.h"
 
 #define XML_DECLARATION_BITS_DECLARATION_EXISTS   (1 << 0)
 #define XML_DECLARATION_BITS_ENCODING_EXISTS      (1 << 1)
@@ -385,24 +384,16 @@ public:
 
   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) override;
 
   /**
    * Get the script loader for this document
    */
   virtual mozilla::dom::ScriptLoader* ScriptLoader() override;
 
-  /**
-   * Add/Remove an element to the document's id and name hashes
-   */
-  virtual void AddToIdTable(Element* aElement, nsAtom* aId) override;
-  virtual void RemoveFromIdTable(Element* aElement, nsAtom* aId) override;
-  virtual void AddToNameTable(Element* aElement, nsAtom* aName) override;
-  virtual void RemoveFromNameTable(Element* aElement, nsAtom* aName) override;
-
   virtual void EndUpdate(nsUpdateType aUpdateType) override;
   virtual void BeginLoad() override;
   virtual void EndLoad() override;
 
   virtual void FlushExternalResources(mozilla::FlushType aType) override;
   virtual void SetXMLDeclaration(const char16_t *aVersion,
                                  const char16_t *aEncoding,
                                  const int32_t aStandalone) override;
@@ -739,18 +730,16 @@ protected:
   // That will stop us from doing a lot of work as each element is removed.
   void DestroyElementMaps();
 
   nsIContent* GetFirstBaseNodeWithHref();
   nsresult SetFirstBaseNodeWithHref(nsIContent *node);
 
 public:
 
-  js::ExpandoAndGeneration mExpandoAndGeneration;
-
   bool ContainsEMEContent();
 
   bool ContainsMSEContent();
 
 protected:
 
   void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget,
                               const nsAString& aType,
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef nsIDocument_h___
 #define nsIDocument_h___
 
+#include "jsfriendapi.h"
 #include "mozilla/FlushType.h"           // for enum
 #include "nsAutoPtr.h"                   // for member
 #include "nsCOMArray.h"                  // for member
 #include "nsCompatibility.h"             // for member
 #include "nsCOMPtr.h"                    // for member
 #include "nsGkAtoms.h"                   // for static class members
 #include "nsIDocumentObserver.h"         // for typedef (nsUpdateType)
 #include "nsILoadGroup.h"                // for member (in nsCOMPtr)
@@ -1598,20 +1599,20 @@ public:
   /**
    * Get the script loader for this document
    */
   virtual mozilla::dom::ScriptLoader* ScriptLoader() = 0;
 
   /**
    * Add/Remove an element to the document's id and name hashes
    */
-  virtual void AddToIdTable(Element* aElement, nsAtom* aId) = 0;
-  virtual void RemoveFromIdTable(Element* aElement, nsAtom* aId) = 0;
-  virtual void AddToNameTable(Element* aElement, nsAtom* aName) = 0;
-  virtual void RemoveFromNameTable(Element* aElement, nsAtom* aName) = 0;
+  void AddToIdTable(Element* aElement, nsAtom* aId);
+  void RemoveFromIdTable(Element* aElement, nsAtom* aId);
+  void AddToNameTable(Element* aElement, nsAtom* aName);
+  void RemoveFromNameTable(Element* aElement, nsAtom* aName);
 
   /**
    * Returns all elements in the fullscreen stack in the insertion order.
    */
   nsTArray<Element*> GetFullscreenStack() const;
 
   /**
    * Asynchronously requests that the document make aElement the fullscreen
@@ -4048,16 +4049,20 @@ protected:
   nsTArray<nsWeakPtr> mFullScreenStack;
 
   // The root of the doc tree in which this document is in. This is only
   // non-null when this document is in fullscreen mode.
   nsWeakPtr mFullscreenRoot;
 
   RefPtr<mozilla::dom::DOMImplementation> mDOMImplementation;
 
+public:
+  js::ExpandoAndGeneration mExpandoAndGeneration;
+
+protected:
   nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
   nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
 
   // Member to store out last-selected stylesheet set.
   nsString mLastStyleSheetSet;
   RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
 
   // We lazily calculate declaration blocks for SVG elements with mapped