Bug 474369 - get rid of nsVoidArray, rdf part; r+sr=bsmedberg
authorArpad Borsos <arpad.borsos@googlemail.com>
Wed, 22 Apr 2009 10:43:15 +0200
changeset 28069 fb3b3f21f8026ff7d6df816dd91b9630c4da7014
parent 28068 0ba03471b3b02f86998ba1d9cdddbef7eb3073bc
child 28070 67ca4255c3410cf9c4afbc6e574a7405409dcce0
push idunknown
push userunknown
push dateunknown
bugs474369
milestone1.9.2a1pre
Bug 474369 - get rid of nsVoidArray, rdf part; r+sr=bsmedberg
rdf/base/src/nsCompositeDataSource.cpp
rdf/base/src/nsInMemoryDataSource.cpp
rdf/base/src/nsRDFContentSink.cpp
rdf/base/src/nsRDFXMLSerializer.cpp
rdf/datasource/public/nsIRDFFileSystem.h
rdf/datasource/src/nsFileSystemDataSource.cpp
--- a/rdf/base/src/nsCompositeDataSource.cpp
+++ b/rdf/base/src/nsCompositeDataSource.cpp
@@ -66,17 +66,17 @@
 #include "nsCOMPtr.h"
 #include "nsIComponentManager.h"
 #include "nsIEnumerator.h"
 #include "nsIRDFCompositeDataSource.h"
 #include "nsIRDFNode.h"
 #include "nsIRDFObserver.h"
 #include "nsIRDFRemoteDataSource.h"
 #include "nsFixedSizeAllocator.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsXPIDLString.h"
 #include "rdf.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "nsEnumeratorUtils.h"
 
@@ -170,17 +170,17 @@ protected:
 
     virtual ~CompositeEnumeratorImpl();
     
     CompositeDataSourceImpl* mCompositeDataSource;
 
     nsISimpleEnumerator* mCurrent;
     nsIRDFNode*  mResult;
     PRInt32      mNext;
-    nsAutoVoidArray  mAlreadyReturned;
+    nsAutoTArray<nsCOMPtr<nsIRDFNode>, 8>  mAlreadyReturned;
     PRPackedBool mAllowNegativeAssertions;
     PRPackedBool mCoalesceDuplicateArcs;
 };
 
 
 CompositeEnumeratorImpl::CompositeEnumeratorImpl(CompositeDataSourceImpl* aCompositeDataSource,
                                                  PRBool aAllowNegativeAssertions,
                                                  PRBool aCoalesceDuplicateArcs)
@@ -192,25 +192,16 @@ CompositeEnumeratorImpl::CompositeEnumer
       mCoalesceDuplicateArcs(aCoalesceDuplicateArcs)
 {
 	NS_ADDREF(mCompositeDataSource);
 }
 
 
 CompositeEnumeratorImpl::~CompositeEnumeratorImpl(void)
 {
-	if (mCoalesceDuplicateArcs == PR_TRUE)
-	{
-		for (PRInt32 i = mAlreadyReturned.Count() - 1; i >= 0; --i)
-		{
-			nsIRDFNode *node = (nsIRDFNode *) mAlreadyReturned[i];
-			NS_RELEASE(node);
-		}
-	}
-
 	NS_IF_RELEASE(mCurrent);
 	NS_IF_RELEASE(mResult);
 	NS_RELEASE(mCompositeDataSource);
 }
 
 NS_IMPL_ADDREF(CompositeEnumeratorImpl)
 NS_IMPL_RELEASE_WITH_DESTROY(CompositeEnumeratorImpl, Destroy())
 NS_IMPL_QUERY_INTERFACE1(CompositeEnumeratorImpl, nsISimpleEnumerator)
@@ -299,17 +290,17 @@ CompositeEnumeratorImpl::HasMoreElements
                 }
             }
 
             if (mCoalesceDuplicateArcs == PR_TRUE)
             {
                 // Now see if we've returned it once already.
                 // XXX N.B. performance here...may want to hash if things get large?
                 PRBool alreadyReturned = PR_FALSE;
-                for (i = mAlreadyReturned.Count() - 1; i >= 0; --i)
+                for (i = mAlreadyReturned.Length() - 1; i >= 0; --i)
                 {
                     if (mAlreadyReturned[i] == mResult)
                     {
                         alreadyReturned = PR_TRUE;
                         break;
                     }
                 }
                 if (alreadyReturned == PR_TRUE)
@@ -327,17 +318,16 @@ CompositeEnumeratorImpl::HasMoreElements
 
             // XXX I wonder if we should make unique-checking be
             // optional. This could get to be pretty expensive (this
             // implementation turns iteration into O(n^2)).
 
             if (mCoalesceDuplicateArcs == PR_TRUE)
             {
                 mAlreadyReturned.AppendElement(mResult);
-                NS_ADDREF(mResult);
             }
 
             return NS_OK;
         } while (1);
     }
 
     // if we get here, there aren't any elements left.
     *aResult = PR_FALSE;
--- a/rdf/base/src/nsInMemoryDataSource.cpp
+++ b/rdf/base/src/nsInMemoryDataSource.cpp
@@ -80,17 +80,17 @@
 #include "nsIRDFInMemoryDataSource.h"
 #include "nsIRDFPropagatableDataSource.h"
 #include "nsIRDFPurgeableDataSource.h"
 #include "nsIRDFService.h"
 #include "nsIServiceManager.h"
 #include "nsISupportsArray.h"
 #include "nsCOMArray.h"
 #include "nsEnumeratorUtils.h"
-#include "nsVoidArray.h"  // XXX introduces dependency on raptorbase
+#include "nsTArray.h"
 #include "nsCRT.h"
 #include "nsRDFCID.h"
 #include "nsRDFBaseDataSources.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsXPIDLString.h"
 #include "nsFixedSizeAllocator.h"
 #include "rdfutil.h"
@@ -645,17 +645,17 @@ private:
     // Hide so that only Create() and Destroy() can be used to
     // allocate and deallocate from the heap
     static void* operator new(size_t) CPP_THROW_NEW { return 0; }
     static void operator delete(void*, size_t) {}
 
     InMemoryDataSource* mDataSource;
     nsIRDFResource*     mSource;
     nsIRDFNode*         mTarget;
-    nsAutoVoidArray     mAlreadyReturned;
+    nsAutoTArray<nsCOMPtr<nsIRDFResource>, 8> mAlreadyReturned;
     nsIRDFResource*     mCurrent;
     Assertion*          mAssertion;
     nsCOMPtr<nsISupportsArray> mHashArcs;
 
     InMemoryArcsEnumeratorImpl(InMemoryDataSource* aDataSource,
                                nsIRDFResource* aSource,
                                nsIRDFNode* aTarget);
 
@@ -745,21 +745,16 @@ InMemoryArcsEnumeratorImpl::~InMemoryArc
     --gInstanceCount;
     fprintf(stdout, "%d - RDF: InMemoryArcsEnumeratorImpl\n", gInstanceCount);
 #endif
 
     NS_RELEASE(mDataSource);
     NS_IF_RELEASE(mSource);
     NS_IF_RELEASE(mTarget);
     NS_IF_RELEASE(mCurrent);
-
-    for (PRInt32 i = mAlreadyReturned.Count() - 1; i >= 0; --i) {
-        nsIRDFResource* resource = (nsIRDFResource*) mAlreadyReturned[i];
-        NS_RELEASE(resource);
-    }
 }
 
 NS_IMPL_ADDREF(InMemoryArcsEnumeratorImpl)
 NS_IMPL_RELEASE_WITH_DESTROY(InMemoryArcsEnumeratorImpl, Destroy(this))
 NS_IMPL_QUERY_INTERFACE1(InMemoryArcsEnumeratorImpl, nsISimpleEnumerator)
 
 NS_IMETHODIMP
 InMemoryArcsEnumeratorImpl::HasMoreElements(PRBool* aResult)
@@ -805,17 +800,17 @@ InMemoryArcsEnumeratorImpl::HasMoreEleme
 
             do {
                 mAssertion = (mSource ? mAssertion->mNext :
                         mAssertion->u.as.mInvNext);
             }
             while (mAssertion && (next == mAssertion->u.as.mProperty));
 
             PRBool alreadyReturned = PR_FALSE;
-            for (PRInt32 i = mAlreadyReturned.Count() - 1; i >= 0; --i) {
+            for (PRInt32 i = mAlreadyReturned.Length() - 1; i >= 0; --i) {
                 if (mAlreadyReturned[i] == next) {
                     alreadyReturned = PR_TRUE;
                     break;
                 }
             }
 
             if (! alreadyReturned) {
                 mCurrent = next;
@@ -839,17 +834,16 @@ InMemoryArcsEnumeratorImpl::GetNext(nsIS
     rv = HasMoreElements(&hasMore);
     if (NS_FAILED(rv)) return rv;
 
     if (! hasMore)
         return NS_ERROR_UNEXPECTED;
 
     // Add this to the set of things we've already returned so that we
     // can ensure uniqueness
-    NS_ADDREF(mCurrent);
     mAlreadyReturned.AppendElement(mCurrent);
 
     // Don't AddRef: we "transfer" ownership to the caller
     *aResult = mCurrent;
     mCurrent = nsnull;
 
     return NS_OK;
 }
--- a/rdf/base/src/nsRDFContentSink.cpp
+++ b/rdf/base/src/nsRDFContentSink.cpp
@@ -79,17 +79,17 @@
 #include "nsIRDFContentSink.h"
 #include "nsIRDFNode.h"
 #include "nsIRDFService.h"
 #include "nsIRDFXMLSink.h"
 #include "nsIServiceManager.h"
 #include "nsIURL.h"
 #include "nsIXMLContentSink.h"
 #include "nsRDFCID.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsXPIDLString.h"
 #include "prlog.h"
 #include "prmem.h"
 #include "rdf.h"
 #include "rdfutil.h"
 #include "nsReadableUtils.h"
 #include "nsIExpatSink.h"
 #include "nsCRT.h"
@@ -269,17 +269,24 @@ protected:
 
     nsresult
     PopContext(nsIRDFResource         *&aContext,
                RDFContentSinkState     &aState,
                RDFContentSinkParseMode &aParseMode);
 
     nsIRDFResource* GetContextElement(PRInt32 ancestor = 0);
 
-    nsAutoVoidArray* mContextStack;
+
+    struct RDFContextStackElement {
+        nsCOMPtr<nsIRDFResource> mResource;
+        RDFContentSinkState      mState;
+        RDFContentSinkParseMode  mParseMode;
+    };
+
+    nsAutoTArray<RDFContextStackElement, 8>* mContextStack;
 
     nsIURI*      mDocumentURL;
 };
 
 PRInt32         RDFContentSinkImpl::gRefCnt = 0;
 nsIRDFService*  RDFContentSinkImpl::gRDFService;
 nsIRDFContainerUtils* RDFContentSinkImpl::gRDFContainerUtils;
 nsIRDFResource* RDFContentSinkImpl::kRDF_type;
@@ -374,17 +381,17 @@ RDFContentSinkImpl::~RDFContentSinkImpl(
 
     if (mContextStack) {
         PR_LOG(gLog, PR_LOG_WARNING,
                ("rdfxml: warning! unclosed tag"));
 
         // XXX we should never need to do this, but, we'll write the
         // code all the same. If someone left the content stack dirty,
         // pop all the elements off the stack and release them.
-        PRInt32 i = mContextStack->Count();
+        PRInt32 i = mContextStack->Length();
         while (0 < i--) {
             nsIRDFResource* resource;
             RDFContentSinkState state;
             RDFContentSinkParseMode parseMode;
             PopContext(resource, state, parseMode);
 
 #ifdef PR_LOGGING
             // print some fairly useless debugging info
@@ -532,18 +539,17 @@ RDFContentSinkImpl::HandleEndElement(con
     case eRDFContentSinkState_InPropertyElement: 
       {
         mDataSource->Assert(GetContextElement(1), GetContextElement(0), resource, PR_TRUE);                                          
       } break;
     default:
       break;
   }
   
-  PRInt32 nestLevel = mContextStack->Count();
-  if (nestLevel == 0)
+  if (mContextStack->IsEmpty())
       mState = eRDFContentSinkState_InEpilog;
 
   NS_IF_RELEASE(resource);
   return NS_OK;
 }
  
 NS_IMETHODIMP 
 RDFContentSinkImpl::HandleComment(const PRUnichar *aName)
@@ -1474,81 +1480,69 @@ RDFContentSinkImpl::ReinitContainer(nsIR
     if (NS_FAILED(rv)) return rv;
 
     return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////
 // Content stack management
 
-struct RDFContextStackElement {
-    nsIRDFResource*         mResource;
-    RDFContentSinkState     mState;
-    RDFContentSinkParseMode mParseMode;
-};
-
 nsIRDFResource* 
 RDFContentSinkImpl::GetContextElement(PRInt32 ancestor /* = 0 */)
 {
     if ((nsnull == mContextStack) ||
-        (ancestor >= mContextStack->Count())) {
+        (PRUint32(ancestor) >= mContextStack->Length())) {
         return nsnull;
     }
 
-    RDFContextStackElement* e =
-        static_cast<RDFContextStackElement*>(mContextStack->ElementAt(mContextStack->Count()-ancestor-1));
-
-    return e->mResource;
+    return mContextStack->ElementAt(
+           mContextStack->Length()-ancestor-1).mResource;
 }
 
 PRInt32 
 RDFContentSinkImpl::PushContext(nsIRDFResource         *aResource,
                                 RDFContentSinkState     aState,
                                 RDFContentSinkParseMode aParseMode)
 {
     if (! mContextStack) {
-        mContextStack = new nsAutoVoidArray();
+        mContextStack = new nsAutoTArray<RDFContextStackElement, 8>();
         if (! mContextStack)
             return 0;
     }
 
-    RDFContextStackElement* e = new RDFContextStackElement;
+    RDFContextStackElement* e = mContextStack->AppendElement();
     if (! e)
-        return mContextStack->Count();
+        return mContextStack->Length();
 
-    NS_IF_ADDREF(aResource);
     e->mResource  = aResource;
     e->mState     = aState;
     e->mParseMode = aParseMode;
   
-    mContextStack->AppendElement(static_cast<void*>(e));
-    return mContextStack->Count();
+    return mContextStack->Length();
 }
  
 nsresult
 RDFContentSinkImpl::PopContext(nsIRDFResource         *&aResource,
                                RDFContentSinkState     &aState,
                                RDFContentSinkParseMode &aParseMode)
 {
-    RDFContextStackElement* e;
     if ((nsnull == mContextStack) ||
-        (0 == mContextStack->Count())) {
+        (mContextStack->IsEmpty())) {
         return NS_ERROR_NULL_POINTER;
     }
 
-    PRInt32 i = mContextStack->Count() - 1;
-    e = static_cast<RDFContextStackElement*>(mContextStack->ElementAt(i));
-    mContextStack->RemoveElementAt(i);
+    PRUint32 i = mContextStack->Length() - 1;
+    RDFContextStackElement &e = mContextStack->ElementAt(i);
 
-    // don't bother Release()-ing: call it our implicit AddRef().
-    aResource  = e->mResource;
-    aState     = e->mState;
-    aParseMode = e->mParseMode;
+    aResource  = e.mResource;
+    NS_IF_ADDREF(aResource);
+    aState     = e.mState;
+    aParseMode = e.mParseMode;
 
-    delete e;
+    mContextStack->RemoveElementAt(i);
     return NS_OK;
 }
  
 
 ////////////////////////////////////////////////////////////////////////
 
 nsresult
 NS_NewRDFContentSink(nsIRDFContentSink** aResult)
--- a/rdf/base/src/nsRDFXMLSerializer.cpp
+++ b/rdf/base/src/nsRDFXMLSerializer.cpp
@@ -43,17 +43,17 @@
 
 #include "nsIAtom.h"
 #include "nsIOutputStream.h"
 #include "nsIRDFService.h"
 #include "nsIRDFContainerUtils.h"
 #include "nsIServiceManager.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "rdf.h"
 #include "rdfutil.h"
 
 #include "rdfIDataSource.h"
 
 #include "nsITimelineService.h"
 
 PRInt32 nsRDFXMLSerializer::gRefCnt = 0;
@@ -637,17 +637,17 @@ nsRDFXMLSerializer::SerializeDescription
     if (NS_FAILED(rv)) return rv;
 
     uri.Append('"');
     rv = rdf_BlockingWrite(aStream, uri);
     if (NS_FAILED(rv)) return rv;
 
     // Any value that's a literal we can write out as an inline
     // attribute on the RDF:Description
-    nsAutoVoidArray visited;
+    nsAutoTArray<nsIRDFResource*, 8> visited;
     PRInt32 skipped = 0;
 
     nsCOMPtr<nsISimpleEnumerator> arcs;
     mDataSource->ArcLabelsOut(aResource, getter_AddRefs(arcs));
 
     if (arcs) {
         // Don't re-serialize rdf:type later on
         if (isTypedNode)
@@ -668,17 +668,17 @@ nsRDFXMLSerializer::SerializeDescription
 
             // Ignore properties that pertain to containers; we may be
             // called from SerializeContainer() if the container resource
             // has been assigned non-container properties.
             if (IsContainerProperty(property))
                 continue;
 
             // Only serialize values for the property once.
-            if (visited.IndexOf(property.get()) >= 0)
+            if (visited.Contains(property.get()))
                 continue;
 
             visited.AppendElement(property.get());
 
             SerializeProperty(aStream, aResource, property, PR_TRUE, &skipped);
         }
     }
 
@@ -714,17 +714,17 @@ nsRDFXMLSerializer::SerializeDescription
                 // Ignore properties that pertain to containers; we may be
                 // called from SerializeContainer() if the container
                 // resource has been assigned non-container properties.
                 if (IsContainerProperty(property))
                     continue;
 
                 // have we already seen this property?  If so, don't write it
                 // out again; serialize property will write each instance.
-                if (visited.IndexOf(property.get()) >= 0)
+                if (visited.Contains(property.get()))
                     continue;
 
                 visited.AppendElement(property.get());
 
                 SerializeProperty(aStream, aResource, property, PR_FALSE, &skipped);
             }
         }
 
deleted file mode 100644
--- a/rdf/datasource/public/nsIRDFFileSystem.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef	nsIRDFFileSystem_h__
-#define	nsIRDFFileSystem_h__
-
-#include "nscore.h"
-#include "nsISupports.h"
-#include "nsIRDFNode.h"
-
-class nsVoidArray;
-
-
-#define NS_IRDFFILESYSTEMDATAOURCE_IID \
-{ 0x1222e6f0, 0xa5e3, 0x11d2, { 0x8b, 0x7c, 0x00, 0x80, 0x5f, 0x8a, 0x7d, 0xb5 } }
-
-class nsIRDFFileSystemDataSource : public nsIRDFDataSource
-{
-public:
-};
-
-
-
-#define NS_IRDFFILESYSTEM_IID \
-{ 0x204a1a00, 0xa5e4, 0x11d2, { 0x8b, 0x7c, 0x00, 0x80, 0x5f, 0x8a, 0x7d, 0xb5 } }
-
-class nsIRDFFileSystem : public nsIRDFResource
-{
-public:
-	NS_IMETHOD	GetFolderList(nsIRDFResource *source, nsVoidArray **array) const = 0;
-	NS_IMETHOD	GetName(nsVoidArray **array) const = 0;
-	NS_IMETHOD	GetURL(nsVoidArray **array) const = 0;
-};
-
-
-
-#endif // nsIRDFFileSystem_h__
--- a/rdf/datasource/src/nsFileSystemDataSource.cpp
+++ b/rdf/datasource/src/nsFileSystemDataSource.cpp
@@ -43,17 +43,16 @@
 #include "nsFileSystemDataSource.h"
 
 #include <ctype.h> // for toupper()
 #include <stdio.h>
 #include "nsIEnumerator.h"
 #include "nsIRDFDataSource.h"
 #include "nsIRDFObserver.h"
 #include "nsIServiceManager.h"
-#include "nsVoidArray.h"
 #include "nsXPIDLString.h"
 #include "nsRDFCID.h"
 #include "rdfutil.h"
 #include "plhash.h"
 #include "plstr.h"
 #include "prlong.h"
 #include "prlog.h"
 #include "prmem.h"