From be2baf922d011507c5dd661b8e81297324844bea Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Thu, 29 Nov 2001 08:48:53 +0000 Subject: [PATCH] Fixing bug 112473. Eliminate unnecessary allocations in the CSS parser and speed up NS_NewHTMLReflowCommand() a bit. r=dbaron@fas.harvard.edu, rs=waterson@netscape.com git-svn-id: svn://10.0.0.236/trunk@109187 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/html/style/src/nsCSSParser.cpp | 4 ++-- mozilla/layout/generic/nsHTMLReflowCommand.cpp | 16 +++++++++------- .../layout/html/base/src/nsHTMLReflowCommand.cpp | 16 +++++++++------- mozilla/layout/style/nsCSSParser.cpp | 4 ++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/mozilla/content/html/style/src/nsCSSParser.cpp b/mozilla/content/html/style/src/nsCSSParser.cpp index 5a85b020ab1..9c8e694319e 100644 --- a/mozilla/content/html/style/src/nsCSSParser.cpp +++ b/mozilla/content/html/style/src/nsCSSParser.cpp @@ -625,7 +625,7 @@ CSSParserImpl::ParseStyleAttribute(const nsAReadableString& aAttributeValue, // XXXldb XXXperf nsIUnicharInputStream is horrible! It makes us make // a copy. - nsString* str = new nsString(aAttributeValue); + nsString* str = new nsAutoString(aAttributeValue); if (nsnull == str) { return NS_ERROR_OUT_OF_MEMORY; } @@ -791,7 +791,7 @@ CSSParserImpl::ParseProperty(const nsAReadableString& aPropName, NS_ASSERTION(nsnull != aBaseURL, "need base URL"); NS_ASSERTION(nsnull != aDeclaration, "Need declaration to parse into!"); - nsString* str = new nsString(aPropValue); + nsString* str = new nsAutoString(aPropValue); if (!str) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/layout/generic/nsHTMLReflowCommand.cpp b/mozilla/layout/generic/nsHTMLReflowCommand.cpp index 2b8177828af..19d62790076 100644 --- a/mozilla/layout/generic/nsHTMLReflowCommand.cpp +++ b/mozilla/layout/generic/nsHTMLReflowCommand.cpp @@ -55,16 +55,18 @@ NS_NewHTMLReflowCommand(nsIReflowCommand** aInstancePtrResult, nsIFrame* aChildFrame, nsIAtom* aAttribute) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsHTMLReflowCommand* cmd = new nsHTMLReflowCommand(aTargetFrame, aReflowType, aChildFrame, aAttribute); - if (nsnull == cmd) { + NS_ASSERTION(aInstancePtrResult, + "null result passed to NS_NewHTMLReflowCommand"); + + *aInstancePtrResult = new nsHTMLReflowCommand(aTargetFrame, aReflowType, + aChildFrame, aAttribute); + if (!*aInstancePtrResult) { return NS_ERROR_OUT_OF_MEMORY; } - return cmd->QueryInterface(NS_GET_IID(nsIReflowCommand), (void**)aInstancePtrResult); + NS_ADDREF(*aInstancePtrResult); + + return NS_OK; } #ifdef DEBUG_jesup diff --git a/mozilla/layout/html/base/src/nsHTMLReflowCommand.cpp b/mozilla/layout/html/base/src/nsHTMLReflowCommand.cpp index 2b8177828af..19d62790076 100644 --- a/mozilla/layout/html/base/src/nsHTMLReflowCommand.cpp +++ b/mozilla/layout/html/base/src/nsHTMLReflowCommand.cpp @@ -55,16 +55,18 @@ NS_NewHTMLReflowCommand(nsIReflowCommand** aInstancePtrResult, nsIFrame* aChildFrame, nsIAtom* aAttribute) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsHTMLReflowCommand* cmd = new nsHTMLReflowCommand(aTargetFrame, aReflowType, aChildFrame, aAttribute); - if (nsnull == cmd) { + NS_ASSERTION(aInstancePtrResult, + "null result passed to NS_NewHTMLReflowCommand"); + + *aInstancePtrResult = new nsHTMLReflowCommand(aTargetFrame, aReflowType, + aChildFrame, aAttribute); + if (!*aInstancePtrResult) { return NS_ERROR_OUT_OF_MEMORY; } - return cmd->QueryInterface(NS_GET_IID(nsIReflowCommand), (void**)aInstancePtrResult); + NS_ADDREF(*aInstancePtrResult); + + return NS_OK; } #ifdef DEBUG_jesup diff --git a/mozilla/layout/style/nsCSSParser.cpp b/mozilla/layout/style/nsCSSParser.cpp index 5a85b020ab1..9c8e694319e 100644 --- a/mozilla/layout/style/nsCSSParser.cpp +++ b/mozilla/layout/style/nsCSSParser.cpp @@ -625,7 +625,7 @@ CSSParserImpl::ParseStyleAttribute(const nsAReadableString& aAttributeValue, // XXXldb XXXperf nsIUnicharInputStream is horrible! It makes us make // a copy. - nsString* str = new nsString(aAttributeValue); + nsString* str = new nsAutoString(aAttributeValue); if (nsnull == str) { return NS_ERROR_OUT_OF_MEMORY; } @@ -791,7 +791,7 @@ CSSParserImpl::ParseProperty(const nsAReadableString& aPropName, NS_ASSERTION(nsnull != aBaseURL, "need base URL"); NS_ASSERTION(nsnull != aDeclaration, "Need declaration to parse into!"); - nsString* str = new nsString(aPropValue); + nsString* str = new nsAutoString(aPropValue); if (!str) { return NS_ERROR_OUT_OF_MEMORY; }