Bug 1563066, part 1 - Inline XULContentSinkImpl::CreateElement. r=bzbarsky
authorAndrew McCreight <continuation@gmail.com>
Thu, 04 Jul 2019 00:58:21 +0000
changeset 544038 aafcf88cbefce5083f6448d4d28c2e08367cd8e9
parent 544037 edba0b97649b24f651a6d0a8b678fffff13b09ab
child 544039 700e7a6894f7e444876df14b83ff2d1b4d2a3880
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1563066
milestone69.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 1563066, part 1 - Inline XULContentSinkImpl::CreateElement. r=bzbarsky By adding an optional nodeinfo arg to the nsXULPrototypeElement ctor, the CreateElement method can be easily inlined. Differential Revision: https://phabricator.services.mozilla.com/D36788
dom/xbl/nsXBLContentSink.cpp
dom/xbl/nsXBLPrototypeBinding.cpp
dom/xul/nsXULContentSink.cpp
dom/xul/nsXULContentSink.h
dom/xul/nsXULElement.h
--- a/dom/xbl/nsXBLContentSink.cpp
+++ b/dom/xbl/nsXBLContentSink.cpp
@@ -740,19 +740,18 @@ nsresult nsXBLContentSink::CreateElement
                                            aAppendContent, aFromParser);
 #ifdef MOZ_XUL
   }
 
   // Note that this needs to match the code in
   // nsXBLPrototypeBinding::ReadContentNode.
 
   *aAppendContent = true;
-  RefPtr<nsXULPrototypeElement> prototype = new nsXULPrototypeElement();
-
-  prototype->mNodeInfo = aNodeInfo;
+  RefPtr<nsXULPrototypeElement> prototype =
+      new nsXULPrototypeElement(aNodeInfo);
 
   AddAttributesToXULPrototype(aAtts, aAttsCount, prototype);
 
   Element* result;
   nsresult rv = nsXULElement::CreateFromPrototype(prototype, mDocument, false,
                                                   false, &result);
   *aResult = result;
   return rv;
--- a/dom/xbl/nsXBLPrototypeBinding.cpp
+++ b/dom/xbl/nsXBLPrototypeBinding.cpp
@@ -1008,19 +1008,18 @@ nsresult nsXBLPrototypeBinding::ReadCont
 
   RefPtr<Element> element;
   // Create XUL prototype elements, or regular elements for other namespaces.
   // This needs to match the code in nsXBLContentSink::CreateElement.
 #ifdef MOZ_XUL
   if (namespaceID == kNameSpaceID_XUL) {
     nsIURI* documentURI = aDocument->GetDocumentURI();
 
-    RefPtr<nsXULPrototypeElement> prototype = new nsXULPrototypeElement();
-
-    prototype->mNodeInfo = nodeInfo;
+    RefPtr<nsXULPrototypeElement> prototype =
+        new nsXULPrototypeElement(nodeInfo);
 
     nsXULPrototypeAttribute* attrs = nullptr;
     if (attrCount > 0) {
       attrs = new nsXULPrototypeAttribute[attrCount];
     }
 
     prototype->mAttributes = attrs;
     prototype->mNumAttributes = attrCount;
--- a/dom/xul/nsXULContentSink.cpp
+++ b/dom/xul/nsXULContentSink.cpp
@@ -335,25 +335,16 @@ nsresult XULContentSinkImpl::NormalizeAt
   RefPtr<mozilla::dom::NodeInfo> ni;
   ni = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
                                      nsINode::ATTRIBUTE_NODE);
   aName.SetTo(ni);
 
   return NS_OK;
 }
 
-nsresult XULContentSinkImpl::CreateElement(mozilla::dom::NodeInfo* aNodeInfo,
-                                           nsXULPrototypeElement** aResult) {
-  nsXULPrototypeElement* element = new nsXULPrototypeElement();
-  element->mNodeInfo = aNodeInfo;
-
-  *aResult = element;
-  return NS_OK;
-}
-
 /**** BEGIN NEW APIs ****/
 
 NS_IMETHODIMP
 XULContentSinkImpl::HandleStartElement(const char16_t* aName,
                                        const char16_t** aAtts,
                                        uint32_t aAttsCount,
                                        uint32_t aLineNumber,
                                        uint32_t aColumnNumber) {
@@ -622,46 +613,30 @@ XULContentSinkImpl::ReportError(const ch
 }
 
 nsresult XULContentSinkImpl::OpenRoot(const char16_t** aAttributes,
                                       const uint32_t aAttrLen,
                                       mozilla::dom::NodeInfo* aNodeInfo) {
   NS_ASSERTION(mState == eInProlog, "how'd we get here?");
   if (mState != eInProlog) return NS_ERROR_UNEXPECTED;
 
-  nsresult rv;
-
   if (aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML) ||
       aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XUL)) {
     MOZ_LOG(gContentSinkLog, LogLevel::Error,
             ("xul: script tag not allowed as root content element"));
 
     return NS_ERROR_UNEXPECTED;
   }
 
   // Create the element
-  nsXULPrototypeElement* element;
-  rv = CreateElement(aNodeInfo, &element);
-
-  if (NS_FAILED(rv)) {
-    if (MOZ_LOG_TEST(gContentSinkLog, LogLevel::Error)) {
-      nsAutoString anodeC;
-      aNodeInfo->GetName(anodeC);
-      MOZ_LOG(gContentSinkLog, LogLevel::Error,
-              ("xul: unable to create element '%s' at line %d",
-               NS_ConvertUTF16toUTF8(anodeC).get(),
-               -1));  // XXX pass in line number
-    }
-
-    return rv;
-  }
+  nsXULPrototypeElement* element = new nsXULPrototypeElement(aNodeInfo);
 
   // Push the element onto the context stack, so that child
   // containers will hook up to us as their parent.
-  rv = mContextStack.Push(element, mState);
+  nsresult rv = mContextStack.Push(element, mState);
   if (NS_FAILED(rv)) {
     element->Release();
     return rv;
   }
 
   // Add the attributes
   rv = AddAttributes(aAttributes, aAttrLen, element);
   if (NS_FAILED(rv)) return rv;
@@ -669,37 +644,22 @@ nsresult XULContentSinkImpl::OpenRoot(co
   mState = eInDocumentElement;
   return NS_OK;
 }
 
 nsresult XULContentSinkImpl::OpenTag(const char16_t** aAttributes,
                                      const uint32_t aAttrLen,
                                      const uint32_t aLineNumber,
                                      mozilla::dom::NodeInfo* aNodeInfo) {
-  nsresult rv;
-
   // Create the element
-  nsXULPrototypeElement* element;
-  rv = CreateElement(aNodeInfo, &element);
-
-  if (NS_FAILED(rv)) {
-    if (MOZ_LOG_TEST(gContentSinkLog, LogLevel::Error)) {
-      nsAutoString anodeC;
-      aNodeInfo->GetName(anodeC);
-      MOZ_LOG(gContentSinkLog, LogLevel::Error,
-              ("xul: unable to create element '%s' at line %d",
-               NS_ConvertUTF16toUTF8(anodeC).get(), aLineNumber));
-    }
-
-    return rv;
-  }
+  nsXULPrototypeElement* element = new nsXULPrototypeElement(aNodeInfo);
 
   // Link this element to its parent.
   nsPrototypeArray* children = nullptr;
-  rv = mContextStack.GetTopChildren(&children);
+  nsresult rv = mContextStack.GetTopChildren(&children);
   if (NS_FAILED(rv)) {
     delete element;
     return rv;
   }
 
   // Add the attributes
   rv = AddAttributes(aAttributes, aAttrLen, element);
   if (NS_FAILED(rv)) return rv;
--- a/dom/xul/nsXULContentSink.h
+++ b/dom/xul/nsXULContentSink.h
@@ -81,18 +81,16 @@ class XULContentSinkImpl final : public 
   // Text management
   nsresult FlushText(bool aCreateTextNode = true);
   nsresult AddText(const char16_t* aText, int32_t aLength);
 
   RefPtr<nsNodeInfoManager> mNodeInfoManager;
 
   nsresult NormalizeAttributeString(const char16_t* aExpatName,
                                     nsAttrName& aName);
-  nsresult CreateElement(mozilla::dom::NodeInfo* aNodeInfo,
-                         nsXULPrototypeElement** aResult);
 
  public:
   enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog };
 
  protected:
   State mState;
 
   // content stack management
--- a/dom/xul/nsXULElement.h
+++ b/dom/xul/nsXULElement.h
@@ -128,18 +128,19 @@ class nsXULPrototypeNode {
 
  protected:
   explicit nsXULPrototypeNode(Type aType) : mType(aType) {}
   virtual ~nsXULPrototypeNode() {}
 };
 
 class nsXULPrototypeElement : public nsXULPrototypeNode {
  public:
-  nsXULPrototypeElement()
+  explicit nsXULPrototypeElement(mozilla::dom::NodeInfo* aNodeInfo = nullptr)
       : nsXULPrototypeNode(eType_Element),
+        mNodeInfo(aNodeInfo),
         mNumAttributes(0),
         mHasIdAttribute(false),
         mHasClassAttribute(false),
         mHasStyleAttribute(false),
         mAttributes(nullptr),
         mIsAtom(nullptr) {}
 
   virtual ~nsXULPrototypeElement() { Unlink(); }