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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew McCreight 2019-07-04 00:58:21 +00:00
parent ddd8e853b4
commit 15f2a54f9e
5 changed files with 10 additions and 53 deletions

View File

@ -745,9 +745,8 @@ nsresult nsXBLContentSink::CreateElement(
// nsXBLPrototypeBinding::ReadContentNode.
*aAppendContent = true;
RefPtr<nsXULPrototypeElement> prototype = new nsXULPrototypeElement();
prototype->mNodeInfo = aNodeInfo;
RefPtr<nsXULPrototypeElement> prototype =
new nsXULPrototypeElement(aNodeInfo);
AddAttributesToXULPrototype(aAtts, aAttsCount, prototype);

View File

@ -1013,9 +1013,8 @@ nsresult nsXBLPrototypeBinding::ReadContentNode(nsIObjectInputStream* aStream,
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) {

View File

@ -340,15 +340,6 @@ nsresult XULContentSinkImpl::NormalizeAttributeString(
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
@ -627,8 +618,6 @@ nsresult XULContentSinkImpl::OpenRoot(const char16_t** aAttributes,
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,
@ -638,25 +627,11 @@ nsresult XULContentSinkImpl::OpenRoot(const char16_t** aAttributes,
}
// 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;
@ -674,27 +649,12 @@ 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;

View File

@ -86,8 +86,6 @@ class XULContentSinkImpl final : public nsIXMLContentSink, public nsIExpatSink {
nsresult NormalizeAttributeString(const char16_t* aExpatName,
nsAttrName& aName);
nsresult CreateElement(mozilla::dom::NodeInfo* aNodeInfo,
nsXULPrototypeElement** aResult);
public:
enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog };

View File

@ -133,8 +133,9 @@ class 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),