From 5694df2cdec7855dd3f215449dd89bc5b3f59669 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Mon, 9 Jun 2003 18:48:15 +0000 Subject: [PATCH] Bug 206338: improve txStack performance by inlining functions and moving bounds-check to outside the txStack-class r=Pike sr=peterv git-svn-id: svn://10.0.0.236/trunk@143471 18797224-902f-48f8-a5cc-f745e15eee43 --- .../transformiix/source/base/txStack.h | 31 +++++++++---------- .../transformiix/source/xslt/txHTMLOutput.cpp | 20 ++++++------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/mozilla/extensions/transformiix/source/base/txStack.h b/mozilla/extensions/transformiix/source/base/txStack.h index 560e3bd8d22..126631a0fa3 100644 --- a/mozilla/extensions/transformiix/source/base/txStack.h +++ b/mozilla/extensions/transformiix/source/base/txStack.h @@ -51,12 +51,10 @@ public: * * @return a pointer to the object that is the top of this stack. */ - void* peek() + inline void* peek() { - PRInt32 count = Count() - 1; - NS_ENSURE_TRUE(count >= 0, nsnull); - - return ElementAt(count); + NS_ASSERTION(!isEmpty(), "peeking at empty stack"); + return ElementAt(Count() - 1); } /** @@ -65,9 +63,10 @@ public: * @param obj a pointer to the object that is to be added to the * top of this stack. */ - nsresult push(void* aObject) + inline nsresult push(void* aObject) { - return AppendElement(aObject); + return InsertElementAt(aObject, Count()) ? NS_OK : + NS_ERROR_OUT_OF_MEMORY; } /** @@ -76,13 +75,12 @@ public: * * @return a pointer to the object that was the top of this stack. */ - void* pop() + inline void* pop() { - PRInt32 count = Count() - 1; - NS_ENSURE_TRUE(count >= 0, nsnull); - + NS_ASSERTION(!isEmpty(), "popping from empty stack"); + const PRInt32 count = Count() - 1; void* object = ElementAt(count); - RemoveElementAt(count); + RemoveElementsAt(count, 1); return object; } @@ -91,7 +89,7 @@ public: * * @return true if there are no objects in the stack. */ - PRBool isEmpty() + inline PRBool isEmpty() { return (Count() <= 0); } @@ -101,7 +99,7 @@ public: * * @return the number of elements in the Stack. */ - PRInt32 size() + inline PRInt32 size() { return Count(); } @@ -118,6 +116,7 @@ public: * * @param aStack the stack to create an iterator for. */ + inline txStackIterator(txStack* aStack) : mStack(aStack), mPosition(0) { @@ -128,7 +127,7 @@ public: * * @return . */ - PRBool hasNext() + inline PRBool hasNext() { return (mPosition < mStack->Count()); } @@ -138,7 +137,7 @@ public: * * @return . */ - void* next() + inline void* next() { if (mPosition == mStack->Count()) { return nsnull; diff --git a/mozilla/extensions/transformiix/source/xslt/txHTMLOutput.cpp b/mozilla/extensions/transformiix/source/xslt/txHTMLOutput.cpp index ff9db5431c1..4b7f6b197a7 100644 --- a/mozilla/extensions/transformiix/source/xslt/txHTMLOutput.cpp +++ b/mozilla/extensions/transformiix/source/xslt/txHTMLOutput.cpp @@ -245,17 +245,17 @@ void txHTMLOutput::characters(const nsAString& aData, PRBool aDOE) } // Special-case script and style - txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek(); - if (currentElement && - (currentElement->mNamespaceID == kNameSpaceID_None) && - ((currentElement->mLocalName == txHTMLAtoms::script) || - (currentElement->mLocalName == txHTMLAtoms::style))) { - closeStartTag(MB_FALSE); - printUTF8Chars(aData); - } - else { - txXMLOutput::characters(aData, aDOE); + if (!mCurrentElements.isEmpty()) { + txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek(); + if (currentElement->mNamespaceID == kNameSpaceID_None && + (currentElement->mLocalName == txHTMLAtoms::script || + currentElement->mLocalName == txHTMLAtoms::style)) { + closeStartTag(MB_FALSE); + printUTF8Chars(aData); + return; + } } + txXMLOutput::characters(aData, aDOE); } void txHTMLOutput::endElement(const nsAString& aName,