Bug 474369 - get rid of nsVoidArray, parser part; r+sr=mrbkap
authorArpad Borsos <arpad.borsos@googlemail.com>
Wed, 25 Mar 2009 09:13:05 +0100
changeset 26581 803af1db1238bf1473b02e719a9b379f32619568
parent 26580 a317451ea31eab6b980c1a0335477e627957af39
child 26582 f35e586819512327f0963e36f24b112da27ab2ef
push id6122
push userarpad.borsos@googlemail.com
push dateWed, 25 Mar 2009 08:40:38 +0000
treeherdermozilla-central@931671e83e44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs474369
milestone1.9.2a1pre
Bug 474369 - get rid of nsVoidArray, parser part; r+sr=mrbkap
parser/htmlparser/public/nsIElementObserver.h
parser/htmlparser/src/CNavDTD.cpp
parser/htmlparser/src/CNavDTD.h
parser/htmlparser/src/nsDTDUtils.cpp
parser/htmlparser/src/nsDTDUtils.h
parser/htmlparser/src/nsParserService.h
--- a/parser/htmlparser/public/nsIElementObserver.h
+++ b/parser/htmlparser/public/nsIElementObserver.h
@@ -43,17 +43,16 @@
  */
 
 #ifndef nsIElementObserver_h__
 #define nsIElementObserver_h__
 
 #include "nsISupports.h"
 #include "prtypes.h"
 #include "nsHTMLTags.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 
 
 // {4672AA04-F6AE-11d2-B3B7-00805F8A6670}
 #define NS_IELEMENTOBSERVER_IID      \
 { 0x4672aa04, 0xf6ae, 0x11d2, { 0xb3, 0xb7, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 
 
--- a/parser/htmlparser/src/CNavDTD.cpp
+++ b/parser/htmlparser/src/CNavDTD.cpp
@@ -51,17 +51,16 @@
 #include "plstr.h"
 #include "nsDTDUtils.h"
 #include "nsHTMLTokenizer.h"
 #include "nsTime.h"
 #include "nsParserNode.h"
 #include "nsHTMLEntities.h"
 #include "nsLinebreakConverter.h"
 #include "nsIFormProcessor.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "prmem.h"
 #include "nsIServiceManager.h"
 
 #ifdef NS_DEBUG
 #include "nsLoggingSink.h"
--- a/parser/htmlparser/src/CNavDTD.h
+++ b/parser/htmlparser/src/CNavDTD.h
@@ -95,17 +95,16 @@
  */
 #ifndef NS_NAVHTMLDTD__
 #define NS_NAVHTMLDTD__
 
 #include "nsIDTD.h"
 #include "nsISupports.h"
 #include "nsIParser.h"
 #include "nsHTMLTags.h"
-#include "nsVoidArray.h"
 #include "nsDeque.h"
 #include "nsParserCIID.h"
 #include "nsTime.h"
 #include "nsDTDUtils.h"
 #include "nsParser.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsIHTMLContentSink;
--- a/parser/htmlparser/src/nsDTDUtils.cpp
+++ b/parser/htmlparser/src/nsDTDUtils.cpp
@@ -1037,21 +1037,16 @@ NS_IMPL_ISUPPORTS1(nsObserverEntry, nsIO
 nsObserverEntry::nsObserverEntry(const nsAString& aTopic) : mTopic(aTopic) 
 {
   memset(mObservers, 0, sizeof(mObservers));
 }
 
 nsObserverEntry::~nsObserverEntry() {
   for (PRInt32 i = 0; i <= NS_HTML_TAG_MAX; ++i){
     if (mObservers[i]) {
-      PRInt32 count = mObservers[i]->Count();
-      for (PRInt32 j = 0; j < count; ++j) {
-        nsISupports* obs = (nsISupports*)mObservers[i]->ElementAt(j);
-        NS_IF_RELEASE(obs);
-      }
       delete mObservers[i];
     }
   }
 }
 
 NS_IMETHODIMP
 nsObserverEntry::Notify(nsIParserNode* aNode,
                         nsIParser* aParser,
@@ -1060,25 +1055,25 @@ nsObserverEntry::Notify(nsIParserNode* a
 {
   NS_ENSURE_ARG_POINTER(aNode);
   NS_ENSURE_ARG_POINTER(aParser);
 
   nsresult result = NS_OK;
   eHTMLTags theTag = (eHTMLTags)aNode->GetNodeType();
  
   if (theTag <= NS_HTML_TAG_MAX) {
-    nsVoidArray*  theObservers = mObservers[theTag];
+    nsCOMArray<nsIElementObserver>* theObservers = mObservers[theTag];
     if (theObservers) {
       PRInt32   theCharsetSource;
       nsCAutoString      charset;
       aParser->GetDocumentCharset(charset,theCharsetSource);
       NS_ConvertASCIItoUTF16 theCharsetValue(charset);
 
       PRInt32 theAttrCount = aNode->GetAttributeCount(); 
-      PRInt32 theObserversCount = theObservers->Count(); 
+      PRInt32 theObserversCount = theObservers->Count();
       if (0 < theObserversCount){
         nsTArray<nsString> keys(theAttrCount + 4), values(theAttrCount + 4);
 
         // XXX this and the following code may be a performance issue.
         // Every key and value is copied and added to an voidarray (causing at
         // least 2 allocations for mImpl, usually more, plus at least 1 per
         // string (total = 2*(keys+3) + 2(or more) array allocations )).
         PRInt32 index;
@@ -1098,17 +1093,17 @@ nsObserverEntry::Notify(nsIParserNode* a
 
         keys.AppendElement(NS_LITERAL_STRING("X_COMMAND"));
         values.AppendElement(NS_LITERAL_STRING("text/html")); 
 
         nsCOMPtr<nsIChannel> channel;
         aParser->GetChannel(getter_AddRefs(channel));
 
         for (index=0;index<theObserversCount;++index) {
-          nsIElementObserver* observer = static_cast<nsIElementObserver*>(theObservers->ElementAt(index));
+          nsIElementObserver* observer = theObservers->ObjectAt(index);
           if (observer) {
             result = observer->Notify(aWebShell, channel,
                                       nsHTMLTags::GetStringValue(theTag),
                                       &keys, &values, aFlags);
             if (NS_FAILED(result)) {
               break;
             }
 
@@ -1133,32 +1128,27 @@ nsObserverEntry::Matches(const nsAString
 }
 
 nsresult
 nsObserverEntry::AddObserver(nsIElementObserver *aObserver,
                              eHTMLTags aTag) 
 {
   if (aObserver) {
     if (!mObservers[aTag]) {
-      mObservers[aTag] = new nsAutoVoidArray();
+      mObservers[aTag] = new nsCOMArray<nsIElementObserver>();
       if (!mObservers[aTag]) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
     }
-    NS_ADDREF(aObserver);
-    mObservers[aTag]->AppendElement(aObserver);
+    mObservers[aTag]->AppendObject(aObserver);
   }
   return NS_OK;
 }
 
 void 
 nsObserverEntry::RemoveObserver(nsIElementObserver *aObserver)
 {
   for (PRInt32 i=0; i <= NS_HTML_TAG_MAX; ++i){
     if (mObservers[i]) {
-      nsISupports* obs = aObserver;
-      PRBool removed = mObservers[i]->RemoveElement(obs);
-      if (removed) {
-        NS_RELEASE(obs);
-      }
+      mObservers[i]->RemoveObject(aObserver);
     }
   }
 }
--- a/parser/htmlparser/src/nsDTDUtils.h
+++ b/parser/htmlparser/src/nsDTDUtils.h
@@ -53,17 +53,17 @@
 #include "nsIParser.h"
 #include "nsCRT.h"
 #include "nsDeque.h"
 #include "nsIDTD.h"
 #include "nsITokenizer.h"
 #include "nsString.h"
 #include "nsIParserNode.h"
 #include "nsFixedSizeAllocator.h"
-#include "nsVoidArray.h"
+#include "nsCOMArray.h"
 #include "nsIParserService.h"
 #include "nsReadableUtils.h"
 #include "nsIHTMLContentSink.h"
 
 #define IF_HOLD(_ptr) \
  PR_BEGIN_MACRO       \
  if(_ptr) {           \
    _ptr->AddRef();    \
@@ -439,17 +439,17 @@ public:
                     const PRUint32 aFlags);
 
   nsresult   AddObserver(nsIElementObserver* aObserver,eHTMLTags aTag);
   void       RemoveObserver(nsIElementObserver* aObserver);
   PRBool     Matches(const nsAString& aTopic);
 
 protected:
   nsString mTopic;
-  nsVoidArray* mObservers[NS_HTML_TAG_MAX + 1];
+  nsCOMArray<nsIElementObserver>* mObservers[NS_HTML_TAG_MAX + 1];
   friend class nsMatchesTopic;
 };
 
 /*********************************************************************************************/
 
 
 struct TagList {
   PRUint32 mCount;
--- a/parser/htmlparser/src/nsParserService.h
+++ b/parser/htmlparser/src/nsParserService.h
@@ -35,17 +35,16 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef NS_PARSERSERVICE_H__
 #define NS_PARSERSERVICE_H__
 
 #include "nsIParserService.h"
 #include "nsDTDUtils.h"
-#include "nsVoidArray.h"
 
 extern "C" int MOZ_XMLIsLetter(const char* ptr);
 extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
 extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
                                       const char** next, PRUnichar* result);
 
 class nsParserService : public nsIParserService {
 public: