Bug 474369 - get rid of nsVoidArray, content part; r=jwatt, sr=sicking
authorArpad Borsos <arpad.borsos@googlemail.com>
Fri, 20 Mar 2009 09:15:35 +0100
changeset 26413 659355060532a68662289fc41a052d9134479db9
parent 26412 0da807e1dbac75a2b2ed3cdd2b605f20643ee2ab
child 26414 834d31edda466072384ec06c72192e24df9d73a1
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt, sicking
bugs474369
milestone1.9.2a1pre
Bug 474369 - get rid of nsVoidArray, content part; r=jwatt, sr=sicking
content/base/public/nsContentUtils.h
content/base/public/nsIContent.h
content/base/public/nsINode.h
content/base/public/nsXMLNameSpaceMap.h
content/base/src/nsContentIterator.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsDOMLists.h
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/base/src/nsDocumentEncoder.cpp
content/base/src/nsGenericDOMDataNode.h
content/base/src/nsGenericElement.h
content/base/src/nsHTMLContentSerializer.cpp
content/base/src/nsHTMLContentSerializer.h
content/base/src/nsPlainTextSerializer.cpp
content/base/src/nsPlainTextSerializer.h
content/base/src/nsRange.h
content/base/src/nsScriptEventManager.h
content/base/src/nsStyleLinkElement.cpp
content/base/src/nsTreeWalker.cpp
content/base/src/nsTreeWalker.h
content/base/src/nsXMLContentSerializer.cpp
content/base/src/nsXMLContentSerializer.h
content/base/src/nsXMLNameSpaceMap.cpp
content/html/document/src/nsHTMLContentSink.cpp
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsHTMLDocument.h
content/html/document/src/nsHTMLFragmentContentSink.cpp
content/svg/content/src/nsSVGDataParser.h
content/svg/content/src/nsSVGLengthList.cpp
content/svg/content/src/nsSVGNumberList.cpp
content/svg/content/src/nsSVGPathDataParser.h
content/svg/content/src/nsSVGPathSegList.cpp
content/svg/content/src/nsSVGPointList.cpp
content/svg/content/src/nsSVGPointList.h
content/svg/content/src/nsSVGTransformList.cpp
content/svg/content/src/nsSVGTransformList.h
content/svg/content/src/nsSVGValue.cpp
content/svg/content/src/nsSVGValue.h
content/xbl/src/nsXBLEventHandler.cpp
content/xbl/src/nsXBLEventHandler.h
content/xbl/src/nsXBLService.cpp
content/xml/document/src/nsXMLContentSink.cpp
content/xslt/src/base/txNamespaceMap.cpp
content/xslt/src/base/txNamespaceMap.h
content/xslt/src/base/txStack.h
content/xslt/src/main/testXalan.cpp
content/xslt/src/xml/txDOM.h
content/xslt/src/xml/txNodeDefinition.cpp
content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
content/xslt/src/xpath/txNodeSet.h
content/xslt/src/xpath/txXPathTreeWalker.h
content/xslt/src/xslt/txBufferingHandler.cpp
content/xslt/src/xslt/txBufferingHandler.h
content/xslt/src/xslt/txExecutionState.h
content/xslt/src/xslt/txInstructions.cpp
content/xslt/src/xslt/txInstructions.h
content/xslt/src/xslt/txStylesheetCompiler.cpp
content/xslt/src/xslt/txStylesheetCompiler.h
content/xslt/src/xslt/txXSLTPatterns.h
content/xul/document/src/nsXULContentSink.h
content/xul/document/src/nsXULControllers.cpp
content/xul/document/src/nsXULControllers.h
content/xul/templates/src/nsTemplateRule.h
content/xul/templates/src/nsXULContentBuilder.cpp
content/xul/templates/src/nsXULTemplateBuilder.cpp
content/xul/templates/src/nsXULTemplateBuilder.h
content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h
content/xul/templates/src/nsXULTreeBuilder.cpp
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -94,17 +94,16 @@ class nsILineBreaker;
 class nsIWordBreaker;
 class nsIJSRuntimeService;
 class nsIEventListenerManager;
 class nsIScriptContext;
 class nsIRunnable;
 class nsIInterfaceRequestor;
 template<class E> class nsCOMArray;
 class nsIPref;
-class nsVoidArray;
 struct JSRuntime;
 class nsICaseConversion;
 class nsIUGenCategory;
 class nsIWidget;
 class nsIDragSession;
 class nsPIDOMWindow;
 class nsPIDOMEventTarget;
 #ifdef MOZ_XTF
@@ -207,39 +206,32 @@ public:
    *         otherwise.
    */
   static PRBool ContentIsDescendantOf(nsINode* aPossibleDescendant,
                                       nsINode* aPossibleAncestor);
 
   /*
    * This method fills the |aArray| with all ancestor nodes of |aNode|
    * including |aNode| at the zero index.
-   *
-   * These elements were |nsIDOMNode*|s before casting to |void*| and must
-   * be cast back to |nsIDOMNode*| on usage, or bad things will happen.
    */
   static nsresult GetAncestors(nsIDOMNode* aNode,
-                               nsVoidArray* aArray);
+                               nsTArray<nsIDOMNode*>* aArray);
 
   /*
    * This method fills |aAncestorNodes| with all ancestor nodes of |aNode|
    * including |aNode| (QI'd to nsIContent) at the zero index.
    * For each ancestor, there is a corresponding element in |aAncestorOffsets|
    * which is the IndexOf the child in relation to its parent.
    *
-   * The elements of |aAncestorNodes| were |nsIContent*|s before casting to
-   * |void*| and must be cast back to |nsIContent*| on usage, or bad things
-   * will happen.
-   *
    * This method just sucks.
    */
   static nsresult GetAncestorsAndOffsets(nsIDOMNode* aNode,
                                          PRInt32 aOffset,
-                                         nsVoidArray* aAncestorNodes,
-                                         nsVoidArray* aAncestorOffsets);
+                                         nsTArray<nsIContent*>* aAncestorNodes,
+                                         nsTArray<PRInt32>* aAncestorOffsets);
 
   /*
    * The out parameter, |aCommonAncestor| will be the closest node, if any,
    * to both |aNode| and |aOther| which is also an ancestor of each.
    * Returns an error if the two nodes are disconnected and don't have
    * a common ancestor.
    */
   static nsresult GetCommonAncestor(nsIDOMNode *aNode,
@@ -832,17 +824,17 @@ public:
   static PRBool IsInChromeDocshell(nsIDocument *aDocument);
 
   /**
    * Release *aSupportsPtr when the shutdown notification is received
    */
   static nsresult ReleasePtrOnShutdown(nsISupports** aSupportsPtr) {
     NS_ASSERTION(aSupportsPtr, "Expect to crash!");
     NS_ASSERTION(*aSupportsPtr, "Expect to crash!");
-    return sPtrsToPtrsToRelease->AppendElement(aSupportsPtr) ? NS_OK :
+    return sPtrsToPtrsToRelease->AppendElement(aSupportsPtr) != nsnull ? NS_OK :
       NS_ERROR_OUT_OF_MEMORY;
   }
 
   /**
    * Return the content policy service
    */
   static nsIContentPolicy *GetContentPolicy();
 
@@ -1458,17 +1450,17 @@ private:
   static PRBool sTriedToGetContentPolicy;
 
   static nsILineBreaker* sLineBreaker;
   static nsIWordBreaker* sWordBreaker;
   static nsICaseConversion* sCaseConv;
   static nsIUGenCategory* sGenCat;
 
   // Holds pointers to nsISupports* that should be released at shutdown
-  static nsVoidArray* sPtrsToPtrsToRelease;
+  static nsTArray<nsISupports**>* sPtrsToPtrsToRelease;
 
   static nsIScriptRuntime* sScriptRuntimes[NS_STID_ARRAY_UBOUND];
   static PRInt32 sScriptRootCount[NS_STID_ARRAY_UBOUND];
   static PRUint32 sJSGCThingRootCount;
 
 #ifdef IBMBIDI
   static nsIBidiKeyboard* sBidiKeyboard;
 #endif
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -43,17 +43,16 @@
 #include "nsChangeHint.h"
 #include "nsINode.h"
 #include "nsIProgrammingLanguage.h" // for ::JAVASCRIPT
 
 // Forward declarations
 class nsIAtom;
 class nsIDocument;
 class nsPresContext;
-class nsVoidArray;
 class nsIDOMEvent;
 class nsIContent;
 class nsIEventListenerManager;
 class nsIURI;
 class nsICSSStyleRule;
 class nsRuleWalker;
 class nsAttrValue;
 class nsAttrName;
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -54,17 +54,16 @@ class nsIDOMNodeList;
 class nsINodeList;
 class nsIPresShell;
 class nsPresContext;
 class nsEventChainVisitor;
 class nsEventChainPreVisitor;
 class nsEventChainPostVisitor;
 class nsIEventListenerManager;
 class nsIPrincipal;
-class nsVoidArray;
 class nsIMutationObserver;
 class nsChildContentList;
 class nsNodeWeakReference;
 class nsNodeSupportsWeakRefTearoff;
 class nsIEditor;
 
 enum {
   // This bit will be set if the node doesn't have nsSlots
--- a/content/base/public/nsXMLNameSpaceMap.h
+++ b/content/base/public/nsXMLNameSpaceMap.h
@@ -34,19 +34,21 @@
  * 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 nsXMLNameSpaceMap_h_
 #define nsXMLNameSpaceMap_h_
 
-#include "nsVoidArray.h"
+#include "nsString.h"
+#include "nsTArray.h"
 
 class nsIAtom;
+class nsNameSpaceEntry;
 
 /**
  * nsXMLNameSpaceMap contains a set of prefixes which are mapped onto
  * namespaces.  It allows the set to be searched by prefix or by namespace ID.
  */
 class nsXMLNameSpaceMap
 {
 public:
@@ -89,12 +91,12 @@ public:
   /* Removes all prefix mappings. */
   NS_HIDDEN_(void) Clear();
 
   ~nsXMLNameSpaceMap() { Clear(); }
 
 private:
   nsXMLNameSpaceMap() NS_HIDDEN;  // use Create() to create new instances
 
-  nsVoidArray mNameSpaces;
+  nsTArray<nsNameSpaceEntry*> mNameSpaces;
 };
 
 #endif
--- a/content/base/src/nsContentIterator.cpp
+++ b/content/base/src/nsContentIterator.cpp
@@ -42,17 +42,17 @@
 #include "nsRange.h"
 #include "nsIContent.h"
 #include "nsIDOMText.h"
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
 #include "nsIComponentManager.h"
 #include "nsContentCID.h"
 #include "nsLayoutCID.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsContentUtils.h"
 #include "nsINode.h"
 
 static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
 
 // couple of utility static functs
 
 ///////////////////////////////////////////////////////////////////////////
@@ -150,42 +150,42 @@ public:
   virtual nsresult PositionAt(nsINode* aCurNode);
 
   // nsIEnumertor interface methods ------------------------------
   
   //NS_IMETHOD CurrentItem(nsISupports **aItem);
 
 protected:
 
-  nsINode* GetDeepFirstChild(nsINode *aRoot, nsVoidArray *aIndexes);
-  nsINode* GetDeepLastChild(nsINode *aRoot, nsVoidArray *aIndexes);
+  nsINode* GetDeepFirstChild(nsINode *aRoot, nsTArray<PRInt32> *aIndexes);
+  nsINode* GetDeepLastChild(nsINode *aRoot, nsTArray<PRInt32> *aIndexes);
 
   // Get the next sibling of aNode.  Note that this will generally return null
   // if aNode happens not to be a content node.  That's OK.
-  nsINode* GetNextSibling(nsINode *aNode, nsVoidArray *aIndexes);
+  nsINode* GetNextSibling(nsINode *aNode, nsTArray<PRInt32> *aIndexes);
 
   // Get the prev sibling of aNode.  Note that this will generally return null
   // if aNode happens not to be a content node.  That's OK.
-  nsINode* GetPrevSibling(nsINode *aNode, nsVoidArray *aIndexes);
+  nsINode* GetPrevSibling(nsINode *aNode, nsTArray<PRInt32> *aIndexes);
 
-  nsINode* NextNode(nsINode *aNode, nsVoidArray *aIndexes);
-  nsINode* PrevNode(nsINode *aNode, nsVoidArray *aIndexes);
+  nsINode* NextNode(nsINode *aNode, nsTArray<PRInt32> *aIndexes);
+  nsINode* PrevNode(nsINode *aNode, nsTArray<PRInt32> *aIndexes);
 
   // WARNING: This function is expensive
   nsresult RebuildIndexStack();
 
   void MakeEmpty();
   
   nsCOMPtr<nsINode> mCurNode;
   nsCOMPtr<nsINode> mFirst;
   nsCOMPtr<nsINode> mLast;
   nsCOMPtr<nsINode> mCommonParent;
 
   // used by nsContentIterator to cache indices
-  nsAutoVoidArray mIndexes;
+  nsAutoTArray<PRInt32, 8> mIndexes;
 
   // used by nsSubtreeIterator to cache indices.  Why put them in the base class?
   // Because otherwise I have to duplicate the routines GetNextSibling etc across both classes,
   // with slight variations for caching.  Or alternately, create a base class for the cache
   // itself and have all the cache manipulation go through a vptr.
   // I think this is the best space and speed combo, even though it's ugly.
   PRInt32 mCachedIndex;
   // another note about mCachedIndex: why should the subtree iterator use a trivial cached index
@@ -534,17 +534,17 @@ nsresult nsContentIterator::RebuildIndex
 
   while (current != mCommonParent)
   {
     parent = current->GetNodeParent();
     
     if (!parent)
       return NS_ERROR_FAILURE;
   
-    mIndexes.InsertElementAt(NS_INT32_TO_PTR(parent->IndexOf(current)), 0);
+    mIndexes.InsertElementAt(0, parent->IndexOf(current));
 
     current = parent;
   }
   return NS_OK;
 }
 
 void
 nsContentIterator::MakeEmpty()
@@ -553,41 +553,42 @@ nsContentIterator::MakeEmpty()
   mFirst        = nsnull;
   mLast         = nsnull;
   mCommonParent = nsnull;
   mIsDone       = PR_TRUE;
   mIndexes.Clear();
 }
 
 nsINode*
-nsContentIterator::GetDeepFirstChild(nsINode *aRoot, nsVoidArray *aIndexes)
+nsContentIterator::GetDeepFirstChild(nsINode *aRoot,
+                                     nsTArray<PRInt32> *aIndexes)
 {
   if (!aRoot) {
     return nsnull;
   }
 
   nsINode *n = aRoot;
   nsINode *nChild = n->GetChildAt(0);
 
   while (nChild)
   {
     if (aIndexes)
     {
       // Add this node to the stack of indexes
-      aIndexes->AppendElement(NS_INT32_TO_PTR(0));
+      aIndexes->AppendElement(0);
     }
     n = nChild;
     nChild = n->GetChildAt(0);
   }
 
   return n;
 }
 
 nsINode*
-nsContentIterator::GetDeepLastChild(nsINode *aRoot, nsVoidArray *aIndexes)
+nsContentIterator::GetDeepLastChild(nsINode *aRoot, nsTArray<PRInt32> *aIndexes)
 {
   if (!aRoot) {
     return nsnull;
   }
 
   nsINode *deepLastChild = aRoot;
 
   nsINode *n = aRoot;
@@ -595,46 +596,47 @@ nsContentIterator::GetDeepLastChild(nsIN
 
   while (numChildren)
   {
     nsINode *nChild = n->GetChildAt(--numChildren);
 
     if (aIndexes)
     {
       // Add this node to the stack of indexes
-      aIndexes->AppendElement(NS_INT32_TO_PTR(numChildren));
+      aIndexes->AppendElement(numChildren);
     }
     numChildren = nChild->GetChildCount();
     n = nChild;
 
     deepLastChild = n;
   }
 
   return deepLastChild;
 }
 
 // Get the next sibling, or parents next sibling, or grandpa's next sibling...
 nsINode *
 nsContentIterator::GetNextSibling(nsINode *aNode, 
-                                  nsVoidArray *aIndexes)
+                                  nsTArray<PRInt32> *aIndexes)
 {
   if (!aNode) 
     return nsnull;
 
   nsINode *parent = aNode->GetNodeParent();
   if (!parent)
     return nsnull;
 
-  PRInt32 indx;
+  PRInt32 indx = 0;
 
-  if (aIndexes)
+  NS_ASSERTION(!aIndexes || !aIndexes->IsEmpty(),
+               "ContentIterator stack underflow");
+  if (aIndexes && !aIndexes->IsEmpty())
   {
-    NS_ASSERTION(aIndexes->Count() > 0, "ContentIterator stack underflow");
     // use the last entry on the Indexes array for the current index
-    indx = NS_PTR_TO_INT32((*aIndexes)[aIndexes->Count()-1]);
+    indx = (*aIndexes)[aIndexes->Length()-1];
   }
   else
     indx = mCachedIndex;
 
   // reverify that the index of the current node hasn't changed.
   // not super cheap, but a lot cheaper than IndexOf(), and still O(1).
   // ignore result this time - the index may now be out of range.
   nsINode *sib = parent->GetChildAt(indx);
@@ -643,62 +645,63 @@ nsContentIterator::GetNextSibling(nsINod
     // someone changed our index - find the new index the painful way
     indx = parent->IndexOf(aNode);
   }
 
   // indx is now canonically correct
   if ((sib = parent->GetChildAt(++indx)))
   {
     // update index cache
-    if (aIndexes)
+    if (aIndexes && !aIndexes->IsEmpty())
     {
-      aIndexes->ReplaceElementAt(NS_INT32_TO_PTR(indx),aIndexes->Count()-1);
+      aIndexes->ElementAt(aIndexes->Length()-1) = indx;
     }
     else mCachedIndex = indx;
   }
   else
   {
     if (parent != mCommonParent)
     {
       if (aIndexes)
       {
         // pop node off the stack, go up one level and return parent or fail.
         // Don't leave the index empty, especially if we're
         // returning NULL.  This confuses other parts of the code.
-        if (aIndexes->Count() > 1)
-          aIndexes->RemoveElementAt(aIndexes->Count()-1);
+        if (aIndexes->Length() > 1)
+          aIndexes->RemoveElementAt(aIndexes->Length()-1);
       }
     }
 
     // ok to leave cache out of date here if parent == mCommonParent?
     sib = GetNextSibling(parent, aIndexes);
   }
   
   return sib;
 }
 
 // Get the prev sibling, or parents prev sibling, or grandpa's prev sibling...
 nsINode*
 nsContentIterator::GetPrevSibling(nsINode *aNode, 
-                                  nsVoidArray *aIndexes)
+                                  nsTArray<PRInt32> *aIndexes)
 {
   if (!aNode)
     return nsnull;
 
   nsINode *parent = aNode->GetNodeParent();
   if (!parent)
     return nsnull;
 
-  PRInt32 indx;
+  PRInt32 indx = 0;
 
-  if (aIndexes)
+  NS_ASSERTION(!aIndexes || !aIndexes->IsEmpty(),
+               "ContentIterator stack underflow");
+  if (aIndexes && !aIndexes->IsEmpty())
   {
-    NS_ASSERTION(aIndexes->Count() > 0, "ContentIterator stack underflow");
     // use the last entry on the Indexes array for the current index
-    indx = NS_PTR_TO_INT32((*aIndexes)[aIndexes->Count()-1]);
+    indx = (*aIndexes)[aIndexes->Length()-1];
   }
   else
     indx = mCachedIndex;
 
   // reverify that the index of the current node hasn't changed
   // ignore result this time - the index may now be out of range.
   nsINode *sib = parent->GetChildAt(indx);
   if (sib != aNode)
@@ -706,74 +709,75 @@ nsContentIterator::GetPrevSibling(nsINod
     // someone changed our index - find the new index the painful way
     indx = parent->IndexOf(aNode);
   }
 
   // indx is now canonically correct
   if (indx > 0 && (sib = parent->GetChildAt(--indx)))
   {
     // update index cache
-    if (aIndexes)
+    if (aIndexes && !aIndexes->IsEmpty())
     {
-      aIndexes->ReplaceElementAt(NS_INT32_TO_PTR(indx),aIndexes->Count()-1);
+      aIndexes->ElementAt(aIndexes->Length()-1) = indx;
     }
     else mCachedIndex = indx;
   }
   else if (parent != mCommonParent)
   {
-    if (aIndexes)
+    if (aIndexes && !aIndexes->IsEmpty())
     {
       // pop node off the stack, go up one level and try again.
-      aIndexes->RemoveElementAt(aIndexes->Count()-1);
+      aIndexes->RemoveElementAt(aIndexes->Length()-1);
     }
     return GetPrevSibling(parent, aIndexes);
   }
 
   return sib;
 }
 
 nsINode*
-nsContentIterator::NextNode(nsINode *aNode, nsVoidArray *aIndexes)
+nsContentIterator::NextNode(nsINode *aNode, nsTArray<PRInt32> *aIndexes)
 {
   nsINode *n = aNode;
   nsINode *nextNode = nsnull;
 
   if (mPre)  // if we are a Pre-order iterator, use pre-order
   {
     // if it has children then next node is first child
     if (NodeHasChildren(n))
     {
       nsINode *nFirstChild = n->GetChildAt(0);
 
       // update cache
       if (aIndexes)
       {
         // push an entry on the index stack
-        aIndexes->AppendElement(NS_INT32_TO_PTR(0));
+        aIndexes->AppendElement(0);
       }
       else mCachedIndex = 0;
       
       return nFirstChild;
     }
 
     // else next sibling is next
     nextNode = GetNextSibling(n, aIndexes);
   }
   else  // post-order
   {
     nsINode *parent = n->GetNodeParent();
     nsINode *nSibling = nsnull;
-    PRInt32 indx;
+    PRInt32 indx = 0;
 
     // get the cached index
-    if (aIndexes)
+    NS_ASSERTION(!aIndexes || !aIndexes->IsEmpty(),
+                 "ContentIterator stack underflow");
+    if (aIndexes && !aIndexes->IsEmpty())
     {
-      NS_ASSERTION(aIndexes->Count() > 0, "ContentIterator stack underflow");
       // use the last entry on the Indexes array for the current index
-      indx = NS_PTR_TO_INT32((*aIndexes)[aIndexes->Count()-1]);
+      indx = (*aIndexes)[aIndexes->Length()-1];
     }
     else indx = mCachedIndex;
 
     // reverify that the index of the current node hasn't changed.
     // not super cheap, but a lot cheaper than IndexOf(), and still O(1).
     // ignore result this time - the index may now be out of range.
     if (indx >= 0)
       nSibling = parent->GetChildAt(indx);
@@ -783,62 +787,63 @@ nsContentIterator::NextNode(nsINode *aNo
       indx = parent->IndexOf(n);
     }
 
     // indx is now canonically correct
     nSibling = parent->GetChildAt(++indx);
     if (nSibling)
     {
       // update cache
-      if (aIndexes)
+      if (aIndexes && !aIndexes->IsEmpty())
       {
         // replace an entry on the index stack
-        aIndexes->ReplaceElementAt(NS_INT32_TO_PTR(indx),aIndexes->Count()-1);
+        aIndexes->ElementAt(aIndexes->Length()-1) = indx;
       }
       else mCachedIndex = indx;
       
       // next node is siblings "deep left" child
       return GetDeepFirstChild(nSibling, aIndexes); 
     }
   
     // else it's the parent
     // update cache
     if (aIndexes)
     {
       // pop an entry off the index stack
       // Don't leave the index empty, especially if we're
       // returning NULL.  This confuses other parts of the code.
-      if (aIndexes->Count() > 1)
-        aIndexes->RemoveElementAt(aIndexes->Count()-1);
+      if (aIndexes->Length() > 1)
+        aIndexes->RemoveElementAt(aIndexes->Length()-1);
     }
     else mCachedIndex = 0;   // this might be wrong, but we are better off guessing
     nextNode = parent;
   }
 
   return nextNode;
 }
 
 nsINode*
-nsContentIterator::PrevNode(nsINode *aNode, nsVoidArray *aIndexes)
+nsContentIterator::PrevNode(nsINode *aNode, nsTArray<PRInt32> *aIndexes)
 {
   nsINode *prevNode = nsnull;
   nsINode *n = aNode;
    
   if (mPre)  // if we are a Pre-order iterator, use pre-order
   {
     nsINode *parent = n->GetNodeParent();
     nsINode *nSibling = nsnull;
-    PRInt32 indx;
+    PRInt32 indx = 0;
 
     // get the cached index
-    if (aIndexes)
+    NS_ASSERTION(!aIndexes || !aIndexes->IsEmpty(),
+                 "ContentIterator stack underflow");
+    if (aIndexes && !aIndexes->IsEmpty())
     {
-      NS_ASSERTION(aIndexes->Count() > 0, "ContentIterator stack underflow");
       // use the last entry on the Indexes array for the current index
-      indx = NS_PTR_TO_INT32((*aIndexes)[aIndexes->Count()-1]);
+      indx = (*aIndexes)[aIndexes->Length()-1];
     }
     else indx = mCachedIndex;
 
     // reverify that the index of the current node hasn't changed.
     // not super cheap, but a lot cheaper than IndexOf(), and still O(1).
     // ignore result this time - the index may now be out of range.
     if (indx >= 0)
       nSibling = parent->GetChildAt(indx);
@@ -848,33 +853,33 @@ nsContentIterator::PrevNode(nsINode *aNo
       // someone changed our index - find the new index the painful way
       indx = parent->IndexOf(n);
     }
 
     // indx is now canonically correct
     if (indx && (nSibling = parent->GetChildAt(--indx)))
     {
       // update cache
-      if (aIndexes)
+      if (aIndexes && !aIndexes->IsEmpty())
       {
         // replace an entry on the index stack
-        aIndexes->ReplaceElementAt(NS_INT32_TO_PTR(indx),aIndexes->Count()-1);
+        aIndexes->ElementAt(aIndexes->Length()-1) = indx;
       }
       else mCachedIndex = indx;
       
       // prev node is siblings "deep right" child
       return GetDeepLastChild(nSibling, aIndexes); 
     }
   
     // else it's the parent
     // update cache
-    if (aIndexes)
+    if (aIndexes && !aIndexes->IsEmpty())
     {
       // pop an entry off the index stack
-      aIndexes->RemoveElementAt(aIndexes->Count()-1);
+      aIndexes->RemoveElementAt(aIndexes->Length()-1);
     }
     else mCachedIndex = 0;   // this might be wrong, but we are better off guessing
     prevNode = parent;
   }
   else  // post-order
   {
     PRInt32 numChildren = n->GetChildCount();
   
@@ -882,17 +887,17 @@ nsContentIterator::PrevNode(nsINode *aNo
     if (numChildren)
     {
       nsINode *nLastChild = n->GetChildAt(--numChildren);
 
       // update cache
       if (aIndexes)
       {
         // push an entry on the index stack
-        aIndexes->AppendElement(NS_INT32_TO_PTR(numChildren));
+        aIndexes->AppendElement(numChildren);
       }
       else mCachedIndex = numChildren;
       
       return nLastChild;
     }
 
     // else prev sibling is previous
     prevNode = GetPrevSibling(n, aIndexes);
@@ -1038,51 +1043,51 @@ nsContentIterator::PositionAt(nsINode* a
                               lastNode, lastOffset))
   {
     mIsDone = PR_TRUE;
     return NS_ERROR_FAILURE;
   }
 
   // We can be at ANY node in the sequence.
   // Need to regenerate the array of indexes back to the root or common parent!
-  nsAutoVoidArray      oldParentStack;
-  nsAutoVoidArray      newIndexes;
+  nsAutoTArray<nsINode*, 8>     oldParentStack;
+  nsAutoTArray<PRInt32, 8>      newIndexes;
 
   // Get a list of the parents up to the root, then compare the new node
   // with entries in that array until we find a match (lowest common
   // ancestor).  If no match, use IndexOf, take the parent, and repeat.
   // This avoids using IndexOf() N times on possibly large arrays.  We
   // still end up doing it a fair bit.  It's better to use Clone() if
   // possible.
 
   // we know the depth we're down (though we may not have started at the
   // top).
-  if (!oldParentStack.SizeTo(mIndexes.Count()+1))
+  if (!oldParentStack.SetCapacity(mIndexes.Length()+1))
     return NS_ERROR_FAILURE;
 
-  // We want to loop mIndexes.Count() + 1 times here, because we want to make
+  // We want to loop mIndexes.Length() + 1 times here, because we want to make
   // sure we include mCommonParent in the oldParentStack, for use in the next
   // for loop, and mIndexes only has entries for nodes from tempNode up through
   // an ancestor of tempNode that's a child of mCommonParent.
-  for (PRInt32 i = mIndexes.Count()+1; i > 0 && tempNode; i--)
+  for (PRInt32 i = mIndexes.Length()+1; i > 0 && tempNode; i--)
   {
     // Insert at head since we're walking up
-    oldParentStack.InsertElementAt(tempNode,0);
+    oldParentStack.InsertElementAt(0, tempNode);
 
     nsINode *parent = tempNode->GetNodeParent();
 
     if (!parent)  // this node has no parent, and thus no index
       break;
 
     if (parent == mCurNode)
     {
       // The position was moved to a parent of the current position. 
       // All we need to do is drop some indexes.  Shortcut here.
-      mIndexes.RemoveElementsAt(mIndexes.Count() - oldParentStack.Count(),
-                                oldParentStack.Count());
+      mIndexes.RemoveElementsAt(mIndexes.Length() - oldParentStack.Length(),
+                                oldParentStack.Length());
       mIsDone = PR_FALSE;
       return NS_OK;
     }
     tempNode = parent;
   }
 
   // Ok.  We have the array of old parents.  Look for a match.
   while (newCurNode)
@@ -1090,30 +1095,30 @@ nsContentIterator::PositionAt(nsINode* a
     nsINode *parent = newCurNode->GetNodeParent();
 
     if (!parent)  // this node has no parent, and thus no index
       break;
 
     PRInt32 indx = parent->IndexOf(newCurNode);
 
     // insert at the head!
-    newIndexes.InsertElementAt(NS_INT32_TO_PTR(indx),0);
+    newIndexes.InsertElementAt(0, indx);
 
     // look to see if the parent is in the stack
     indx = oldParentStack.IndexOf(parent);
     if (indx >= 0)
     {
       // ok, the parent IS on the old stack!  Rework things.
       // we want newIndexes to replace all nodes equal to or below the match
-      // Note that index oldParentStack.Count()-1 is the last node, which is
+      // Note that index oldParentStack.Length()-1 is the last node, which is
       // one BELOW the last index in the mIndexes stack.  In other words, we
       // want to remove elements starting at index (indx+1).
-      PRInt32 numToDrop = oldParentStack.Count()-(1+indx);
+      PRInt32 numToDrop = oldParentStack.Length()-(1+indx);
       if (numToDrop > 0)
-        mIndexes.RemoveElementsAt(mIndexes.Count() - numToDrop,numToDrop);
+        mIndexes.RemoveElementsAt(mIndexes.Length() - numToDrop, numToDrop);
       mIndexes.AppendElements(newIndexes);
 
       break;
     }
     newCurNode = parent;
   }
 
   // phew!
@@ -1185,22 +1190,22 @@ protected:
 
   // no copy's or assigns  FIX ME
   nsContentSubtreeIterator(const nsContentSubtreeIterator&);
   nsContentSubtreeIterator& operator=(const nsContentSubtreeIterator&);
 
   nsCOMPtr<nsIDOMRange> mRange;
   // these arrays all typically are used and have elements
 #if 0
-  nsAutoVoidArray mStartNodes;
-  nsAutoVoidArray mStartOffsets;
+  nsAutoTArray<nsIContent*, 8> mStartNodes;
+  nsAutoTArray<PRInt32, 8>     mStartOffsets;
 #endif
 
-  nsAutoVoidArray mEndNodes;
-  nsAutoVoidArray mEndOffsets;
+  nsAutoTArray<nsIContent*, 8> mEndNodes;
+  nsAutoTArray<PRInt32, 8>     mEndOffsets;
 };
 
 nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult);
 
 
 
 
 /******************************************************
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -199,17 +199,17 @@ nsDataHashtable<nsISupportsHashKey, Even
 nsIStringBundleService *nsContentUtils::sStringBundleService;
 nsIStringBundle *nsContentUtils::sStringBundles[PropertiesFile_COUNT];
 nsIContentPolicy *nsContentUtils::sContentPolicyService;
 PRBool nsContentUtils::sTriedToGetContentPolicy = PR_FALSE;
 nsILineBreaker *nsContentUtils::sLineBreaker;
 nsIWordBreaker *nsContentUtils::sWordBreaker;
 nsICaseConversion *nsContentUtils::sCaseConv;
 nsIUGenCategory *nsContentUtils::sGenCat;
-nsVoidArray *nsContentUtils::sPtrsToPtrsToRelease;
+nsTArray<nsISupports**> *nsContentUtils::sPtrsToPtrsToRelease;
 nsIScriptRuntime *nsContentUtils::sScriptRuntimes[NS_STID_ARRAY_UBOUND];
 PRInt32 nsContentUtils::sScriptRootCount[NS_STID_ARRAY_UBOUND];
 PRUint32 nsContentUtils::sJSGCThingRootCount;
 #ifdef IBMBIDI
 nsIBidiKeyboard *nsContentUtils::sBidiKeyboard = nsnull;
 #endif
 PRUint32 nsContentUtils::sScriptBlockerCount = 0;
 PRUint32 nsContentUtils::sRemovableScriptBlockerCount = 0;
@@ -323,17 +323,17 @@ nsContentUtils::Init()
 
   // Ignore failure and just don't load images
   rv = CallGetService("@mozilla.org/image/loader;1", &sImgLoader);
   if (NS_FAILED(rv)) {
     // no image loading for us.  Oh, well.
     sImgLoader = nsnull;
   }
 
-  sPtrsToPtrsToRelease = new nsVoidArray();
+  sPtrsToPtrsToRelease = new nsTArray<nsISupports**>();
   if (!sPtrsToPtrsToRelease) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   if (!InitializeEventTable())
     return NS_ERROR_FAILURE;
 
   if (!sEventListenerManagersHash.ops) {
@@ -860,18 +860,18 @@ nsContentUtils::Shutdown()
 {
   sInitialized = PR_FALSE;
 
   NS_HTMLParanoidFragmentSinkShutdown();
   NS_XHTMLParanoidFragmentSinkShutdown();
 
   NS_IF_RELEASE(sContentPolicyService);
   sTriedToGetContentPolicy = PR_FALSE;
-  PRInt32 i;
-  for (i = 0; i < PRInt32(PropertiesFile_COUNT); ++i)
+  PRUint32 i;
+  for (i = 0; i < PropertiesFile_COUNT; ++i)
     NS_IF_RELEASE(sStringBundles[i]);
   NS_IF_RELEASE(sStringBundleService);
   NS_IF_RELEASE(sConsoleService);
   NS_IF_RELEASE(sDOMScriptObjectFactory);
   if (sJSGCThingRootCount == 0 && sXPConnect)
     NS_RELEASE(sXPConnect);
   NS_IF_RELEASE(sSecurityManager);
   NS_IF_RELEASE(sThreadJSContextStack);
@@ -891,19 +891,18 @@ nsContentUtils::Shutdown()
 #ifdef IBMBIDI
   NS_IF_RELEASE(sBidiKeyboard);
 #endif
 
   delete sEventTable;
   sEventTable = nsnull;
 
   if (sPtrsToPtrsToRelease) {
-    for (i = 0; i < sPtrsToPtrsToRelease->Count(); ++i) {
-      nsISupports** ptrToPtr =
-        static_cast<nsISupports**>(sPtrsToPtrsToRelease->ElementAt(i));
+    for (i = 0; i < sPtrsToPtrsToRelease->Length(); ++i) {
+      nsISupports** ptrToPtr = sPtrsToPtrsToRelease->ElementAt(i);
       NS_RELEASE(*ptrToPtr);
     }
     delete sPtrsToPtrsToRelease;
     sPtrsToPtrsToRelease = nsnull;
   }
 
   if (sEventListenerManagersHash.ops) {
     NS_ASSERTION(sEventListenerManagersHash.entryCount == 0,
@@ -1395,17 +1394,17 @@ nsContentUtils::ContentIsDescendantOf(ns
 
   return PR_FALSE;
 }
 
 
 // static
 nsresult
 nsContentUtils::GetAncestors(nsIDOMNode* aNode,
-                             nsVoidArray* aArray)
+                             nsTArray<nsIDOMNode*>* aArray)
 {
   NS_ENSURE_ARG_POINTER(aNode);
 
   nsCOMPtr<nsIDOMNode> node(aNode);
   nsCOMPtr<nsIDOMNode> ancestor;
 
   do {
     aArray->AppendElement(node.get());
@@ -1415,47 +1414,47 @@ nsContentUtils::GetAncestors(nsIDOMNode*
 
   return NS_OK;
 }
 
 // static
 nsresult
 nsContentUtils::GetAncestorsAndOffsets(nsIDOMNode* aNode,
                                        PRInt32 aOffset,
-                                       nsVoidArray* aAncestorNodes,
-                                       nsVoidArray* aAncestorOffsets)
+                                       nsTArray<nsIContent*>* aAncestorNodes,
+                                       nsTArray<PRInt32>* aAncestorOffsets)
 {
   NS_ENSURE_ARG_POINTER(aNode);
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
 
   if (!content) {
     return NS_ERROR_FAILURE;
   }
 
-  if (aAncestorNodes->Count() != 0) {
+  if (!aAncestorNodes->IsEmpty()) {
     NS_WARNING("aAncestorNodes is not empty");
     aAncestorNodes->Clear();
   }
 
-  if (aAncestorOffsets->Count() != 0) {
+  if (!aAncestorOffsets->IsEmpty()) {
     NS_WARNING("aAncestorOffsets is not empty");
     aAncestorOffsets->Clear();
   }
 
   // insert the node itself
   aAncestorNodes->AppendElement(content.get());
-  aAncestorOffsets->AppendElement(NS_INT32_TO_PTR(aOffset));
+  aAncestorOffsets->AppendElement(aOffset);
 
   // insert all the ancestors
   nsIContent* child = content;
   nsIContent* parent = child->GetParent();
   while (parent) {
     aAncestorNodes->AppendElement(parent);
-    aAncestorOffsets->AppendElement(NS_INT32_TO_PTR(parent->IndexOf(child)));
+    aAncestorOffsets->AppendElement(parent->IndexOf(child));
     child = parent;
     parent = parent->GetParent();
   }
 
   return NS_OK;
 }
 
 // static
--- a/content/base/src/nsDOMLists.h
+++ b/content/base/src/nsDOMLists.h
@@ -42,17 +42,16 @@
  * DOM3 stuff and some interfaces specified by WHATWG.
  */
 
 #ifndef nsDOMLists_h___
 #define nsDOMLists_h___
 
 #include "nsIDOMDOMStringList.h"
 #include "nsIDOMNameList.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "nsString.h"
 
 class nsDOMStringList : public nsIDOMDOMStringList
 {
 public:
   nsDOMStringList();
   virtual ~nsDOMStringList();
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -2816,21 +2816,20 @@ nsDocument::SetDocumentCharacterSet(cons
     if (calias) {
       nsCAutoString canonicalName;
       calias->GetPreferred(aCharSetID, canonicalName);
       NS_ASSERTION(canonicalName.Equals(aCharSetID),
                    "charset name must be canonical");
     }
 #endif
 
-    PRInt32 n = mCharSetObservers.Count();
+    PRInt32 n = mCharSetObservers.Length();
 
     for (PRInt32 i = 0; i < n; i++) {
-      nsIObserver* observer =
-        static_cast<nsIObserver *>(mCharSetObservers.ElementAt(i));
+      nsIObserver* observer = mCharSetObservers.ElementAt(i);
 
       observer->Observe(static_cast<nsIDocument *>(this), "charset",
                         NS_ConvertASCIItoUTF16(aCharSetID).get());
     }
   }
 }
 
 nsresult
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -44,16 +44,17 @@
 
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsCRT.h"
 #include "nsIDocument.h"
 #include "nsWeakReference.h"
 #include "nsWeakPtr.h"
 #include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsHashSets.h"
 #include "nsIDOMXMLDocument.h"
 #include "nsIDOM3Document.h"
 #include "nsIDOMDocumentView.h"
 #include "nsIDOMDocumentXBL.h"
 #include "nsIDOMNSDocument.h"
 #include "nsIDOMNSDocumentStyle.h"
 #include "nsIDOMDocumentRange.h"
@@ -1094,17 +1095,17 @@ protected:
 #endif
 
   nsDocument(const char* aContentType);
   virtual ~nsDocument();
 
   nsCString mReferrer;
   nsString mLastModified;
 
-  nsVoidArray mCharSetObservers;
+  nsTArray<nsIObserver*> mCharSetObservers;
 
   PLDHashTable *mSubDocuments;
 
   // Array of owning references to all children
   nsAttrAndChildArray mChildren;
 
   // Pointer to our parser if we're currently in the process of being
   // parsed into.
--- a/content/base/src/nsDocumentEncoder.cpp
+++ b/content/base/src/nsDocumentEncoder.cpp
@@ -71,16 +71,17 @@
 #include "nsISelectionPrivate.h"
 #include "nsIParserService.h"
 #include "nsIScriptContext.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsContentUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsReadableUtils.h"
+#include "nsTArray.h"
 
 nsresult NS_NewDomSelection(nsISelection **aDomSelection);
 
 enum nsRangeIterationDirection {
   kDirectionOut = -1,
   kDirectionIn = 1
 };
 
@@ -104,19 +105,19 @@ protected:
                                       PRBool aDontSerializeRoot);
   nsresult SerializeNodeEnd(nsIDOMNode* aNode, nsAString& aStr);
   nsresult SerializeRangeToString(nsIDOMRange *aRange,
                                   nsAString& aOutputString);
   nsresult SerializeRangeNodes(nsIDOMRange* aRange, 
                                nsIDOMNode* aNode, 
                                nsAString& aString,
                                PRInt32 aDepth);
-  nsresult SerializeRangeContextStart(const nsVoidArray& aAncestorArray,
+  nsresult SerializeRangeContextStart(const nsTArray<nsIDOMNode*>& aAncestorArray,
                                       nsAString& aString);
-  nsresult SerializeRangeContextEnd(const nsVoidArray& aAncestorArray,
+  nsresult SerializeRangeContextEnd(const nsTArray<nsIDOMNode*>& aAncestorArray,
                                     nsAString& aString);
 
   nsresult FlushText(nsAString& aString, PRBool aForce);
 
   static PRBool IsTag(nsIDOMNode* aNode, nsIAtom* aAtom);
   
   virtual PRBool IncludeInContext(nsIDOMNode *aNode);
 
@@ -134,21 +135,21 @@ protected:
   nsString          mMimeType;
   nsCString         mCharset;
   PRUint32          mFlags;
   PRUint32          mWrapColumn;
   PRUint32          mStartDepth;
   PRUint32          mEndDepth;
   PRInt32           mStartRootIndex;
   PRInt32           mEndRootIndex;
-  nsAutoVoidArray   mCommonAncestors;
-  nsAutoVoidArray   mStartNodes;
-  nsAutoVoidArray   mStartOffsets;
-  nsAutoVoidArray   mEndNodes;
-  nsAutoVoidArray   mEndOffsets;
+  nsAutoTArray<nsIDOMNode*, 8> mCommonAncestors;
+  nsAutoTArray<nsIContent*, 8> mStartNodes;
+  nsAutoTArray<PRInt32, 8>     mStartOffsets;
+  nsAutoTArray<nsIContent*, 8> mEndNodes;
+  nsAutoTArray<PRInt32, 8>     mEndOffsets;
   PRPackedBool      mHaltRangeHint;  
   PRPackedBool      mIsCopying;  // Set to PR_TRUE only while copying
   PRPackedBool      mNodeIsContainer;
 };
 
 NS_IMPL_ADDREF(nsDocumentEncoder)
 NS_IMPL_RELEASE(nsDocumentEncoder)
 
@@ -537,75 +538,75 @@ static PRInt32 IndexOf(nsIDOMNode* aPare
   nsCOMPtr<nsIContent> child(do_QueryInterface(aChild));
 
   if (!parent)
     return -1;
 
   return parent->IndexOf(child);
 }
 
-static inline PRInt32 GetIndex(nsVoidArray& aIndexArray)
+static inline PRInt32 GetIndex(nsTArray<PRInt32>& aIndexArray)
 {
-  PRInt32 count = aIndexArray.Count();
+  PRInt32 count = aIndexArray.Length();
 
   if (count) {
-    return (PRInt32)aIndexArray.ElementAt(count - 1);
+    return aIndexArray.ElementAt(count - 1);
   }
 
   return 0;
 }
 
-static nsresult GetNextNode(nsIDOMNode* aNode, nsVoidArray& aIndexArray,
+static nsresult GetNextNode(nsIDOMNode* aNode, nsTArray<PRInt32>& aIndexArray,
                             nsIDOMNode*& aNextNode,
                             nsRangeIterationDirection& aDirection)
 {
   PRBool hasChildren;
 
   aNextNode = nsnull;
 
   aNode->HasChildNodes(&hasChildren);
 
   if (hasChildren && aDirection == kDirectionIn) {
     ChildAt(aNode, 0, aNextNode);
     NS_ENSURE_TRUE(aNextNode, NS_ERROR_FAILURE);
 
-    aIndexArray.AppendElement((void *)0);
+    aIndexArray.AppendElement(0);
 
     aDirection = kDirectionIn;
   } else if (aDirection == kDirectionIn) {
     aNextNode = aNode;
 
     NS_ADDREF(aNextNode);
 
     aDirection = kDirectionOut;
   } else {
     nsCOMPtr<nsIDOMNode> parent;
 
     aNode->GetParentNode(getter_AddRefs(parent));
     NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
 
-    PRInt32 count = aIndexArray.Count();
+    PRInt32 count = aIndexArray.Length();
 
     if (count) {
-      PRInt32 indx = (PRInt32)aIndexArray.ElementAt(count - 1);
+      PRInt32 indx = aIndexArray.ElementAt(count - 1);
 
       ChildAt(parent, indx + 1, aNextNode);
 
       if (aNextNode)
-        aIndexArray.ReplaceElementAt((void *)(indx + 1), count - 1);
+        aIndexArray.ElementAt(count - 1) = indx + 1;
       else
         aIndexArray.RemoveElementAt(count - 1);
     } else {
       PRInt32 indx = IndexOf(parent, aNode);
 
       if (indx >= 0) {
         ChildAt(parent, indx + 1, aNextNode);
 
         if (aNextNode)
-          aIndexArray.AppendElement((void *)(indx + 1));
+          aIndexArray.AppendElement(indx + 1);
       }
     }
 
     if (aNextNode) {
       aDirection = kDirectionIn;
     } else {
       aDirection = kDirectionOut;
 
@@ -665,22 +666,22 @@ nsDocumentEncoder::SerializeRangeNodes(n
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
   nsresult rv=NS_OK;
   
   // get start and end nodes for this recursion level
   nsCOMPtr<nsIContent> startNode, endNode;
   PRInt32 start = mStartRootIndex - aDepth;
-  if (start >= 0 && start <= mStartNodes.Count())
-    startNode = static_cast<nsIContent *>(mStartNodes[start]);
+  if (start >= 0 && start <= mStartNodes.Length())
+    startNode = mStartNodes[start];
 
   PRInt32 end = mEndRootIndex - aDepth;
-  if (end >= 0 && end <= mEndNodes.Count())
-    endNode = static_cast<nsIContent *>(mEndNodes[end]);
+  if (end >= 0 && end <= mEndNodes.Length())
+    endNode = mEndNodes[end];
 
   if ((startNode != content) && (endNode != content))
   {
     // node is completely contained in range.  Serialize the whole subtree
     // rooted by this node.
     rv = SerializeToStringRecursive(aNode, aString, PR_FALSE);
     NS_ENSURE_SUCCESS(rv, rv);
   }
@@ -723,19 +724,19 @@ nsDocumentEncoder::SerializeRangeNodes(n
         NS_ENSURE_SUCCESS(rv, rv);
       }
       
       // do some calculations that will tell us which children of this
       // node are in the range.
       nsCOMPtr<nsIDOMNode> childAsNode;
       PRInt32 startOffset = 0, endOffset = -1;
       if (startNode == content && mStartRootIndex >= aDepth)
-        startOffset = NS_PTR_TO_INT32(mStartOffsets[mStartRootIndex - aDepth]);
+        startOffset = mStartOffsets[mStartRootIndex - aDepth];
       if (endNode == content && mEndRootIndex >= aDepth)
-        endOffset = NS_PTR_TO_INT32(mEndOffsets[mEndRootIndex - aDepth]) ;
+        endOffset = mEndOffsets[mEndRootIndex - aDepth];
       // generated content will cause offset values of -1 to be returned.  
       PRInt32 j;
       PRUint32 childCount = content->GetChildCount();
 
       if (startOffset == -1) startOffset = 0;
       if (endOffset == -1) endOffset = childCount;
       else
       {
@@ -772,49 +773,49 @@ nsDocumentEncoder::SerializeRangeNodes(n
         NS_ENSURE_SUCCESS(rv, rv); 
       }
     }
   }
   return NS_OK;
 }
 
 nsresult
-nsDocumentEncoder::SerializeRangeContextStart(const nsVoidArray& aAncestorArray,
+nsDocumentEncoder::SerializeRangeContextStart(const nsTArray<nsIDOMNode*>& aAncestorArray,
                                               nsAString& aString)
 {
-  PRInt32 i = aAncestorArray.Count();
+  PRInt32 i = aAncestorArray.Length();
   nsresult rv = NS_OK;
 
   while (i > 0) {
-    nsIDOMNode *node = (nsIDOMNode *)aAncestorArray.ElementAt(--i);
+    nsIDOMNode *node = aAncestorArray.ElementAt(--i);
 
     if (!node)
       break;
 
     if (IncludeInContext(node)) {
       rv = SerializeNodeStart(node, 0, -1, aString);
 
       if (NS_FAILED(rv))
         break;
     }
   }
 
   return rv;
 }
 
 nsresult
-nsDocumentEncoder::SerializeRangeContextEnd(const nsVoidArray& aAncestorArray,
+nsDocumentEncoder::SerializeRangeContextEnd(const nsTArray<nsIDOMNode*>& aAncestorArray,
                                             nsAString& aString)
 {
   PRInt32 i = 0;
-  PRInt32 count = aAncestorArray.Count();
+  PRInt32 count = aAncestorArray.Length();
   nsresult rv = NS_OK;
 
   while (i < count) {
-    nsIDOMNode *node = (nsIDOMNode *)aAncestorArray.ElementAt(i++);
+    nsIDOMNode *node = aAncestorArray.ElementAt(i++);
 
     if (!node)
       break;
 
     if (IncludeInContext(node)) {
       rv = SerializeNodeEnd(node, aString);
 
       if (NS_FAILED(rv))
@@ -1251,42 +1252,42 @@ nsHTMLCopyEncoder::EncodeToStringWithCon
   // now encode common ancestors into aContextString.  Note that the common ancestors
   // will be for the last range in the selection in the case of multirange selections.
   // encoding ancestors every range in a multirange selection in a way that could be 
   // understood by the paste code would be a lot more work to do.  As a practical matter,
   // selections are single range, and the ones that aren't are table cell selections
   // where all the cells are in the same table.
 
   // leaf of ancestors might be text node.  If so discard it.
-  PRInt32 count = mCommonAncestors.Count();
+  PRInt32 count = mCommonAncestors.Length();
   PRInt32 i;
   nsCOMPtr<nsIDOMNode> node;
   if (count > 0)
-    node = static_cast<nsIDOMNode *>(mCommonAncestors.ElementAt(0));
+    node = mCommonAncestors.ElementAt(0);
 
   if (node && IsTextNode(node)) 
   {
     mCommonAncestors.RemoveElementAt(0);
     // don't forget to adjust range depth info
     if (mStartDepth) mStartDepth--;
     if (mEndDepth) mEndDepth--;
     // and the count
     count--;
   }
   
   i = count;
   while (i > 0)
   {
-    node = static_cast<nsIDOMNode *>(mCommonAncestors.ElementAt(--i));
+    node = mCommonAncestors.ElementAt(--i);
     SerializeNodeStart(node, 0, -1, aContextString);
   }
   //i = 0; guaranteed by above
   while (i < count)
   {
-    node = static_cast<nsIDOMNode *>(mCommonAncestors.ElementAt(i++));
+    node = mCommonAncestors.ElementAt(i++);
     SerializeNodeEnd(node, aContextString);
   }
 
   // encode range info : the start and end depth of the selection, where the depth is 
   // distance down in the parent hierarchy.  Later we will need to add leading/trailing
   // whitespace info to this.
   nsAutoString infoString;
   infoString.AppendInt(mStartDepth);
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -42,17 +42,16 @@
 
 #ifndef nsGenericDOMDataNode_h___
 #define nsGenericDOMDataNode_h___
 
 #include "nsIDOMCharacterData.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOM3Text.h"
 #include "nsTextFragment.h"
-#include "nsVoidArray.h"
 #include "nsDOMError.h"
 #include "nsIEventListenerManager.h"
 #include "nsGenericElement.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsContentUtils.h"
 
 #ifdef MOZ_SMIL
 #include "nsISMILAttr.h"
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -71,17 +71,16 @@
 
 class nsIDOMAttr;
 class nsIDOMEventListener;
 class nsIFrame;
 class nsIDOMNamedNodeMap;
 class nsDOMCSSDeclaration;
 class nsIDOMCSSStyleDeclaration;
 class nsIURI;
-class nsVoidArray;
 class nsINodeInfo;
 class nsIControllers;
 class nsIDOMNSFeatureFactory;
 class nsIEventListenerManager;
 class nsIScrollableView;
 class nsContentList;
 struct nsRect;
 
--- a/content/base/src/nsHTMLContentSerializer.cpp
+++ b/content/base/src/nsHTMLContentSerializer.cpp
@@ -96,22 +96,20 @@ nsHTMLContentSerializer::nsHTMLContentSe
   mMayIgnoreLineBreakSequence(PR_FALSE),
   mIsWholeDocument(PR_FALSE),
   mInCDATA(PR_FALSE)
 {
 }
 
 nsHTMLContentSerializer::~nsHTMLContentSerializer()
 {
-  NS_ASSERTION(mOLStateStack.Count() == 0, "Expected OL State stack to be empty");
-  if (mOLStateStack.Count() > 0){
-    for (PRInt32 i = 0; i < mOLStateStack.Count(); i++){
-      olState* state = (olState*)mOLStateStack[i];
-      delete state;
-      mOLStateStack.RemoveElementAt(i);
+  NS_ASSERTION(mOLStateStack.IsEmpty(), "Expected OL State stack to be empty");
+  if (!mOLStateStack.IsEmpty()){
+    for (PRUint32 i = 0; i < mOLStateStack.Length(); i++){
+      delete mOLStateStack[i];
     }
   }
 }
 
 NS_IMETHODIMP 
 nsHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
                               const char* aCharSet, PRBool aIsCopying,
                               PRBool aIsWholeDocument)
@@ -783,22 +781,22 @@ nsHTMLContentSerializer::AppendElementEn
 
   if (name == nsGkAtoms::pre ||
       name == nsGkAtoms::script ||
       name == nsGkAtoms::style) {
     mPreLevel--;
   }
 
   if (mIsCopying && (name == nsGkAtoms::ol)){
-    NS_ASSERTION((mOLStateStack.Count() > 0), "Cannot have an empty OL Stack");
+    NS_ASSERTION(!mOLStateStack.IsEmpty(), "Cannot have an empty OL Stack");
     /* Though at this point we must always have an state to be deleted as all 
     the OL opening tags are supposed to push an olState object to the stack*/
-    if (mOLStateStack.Count() > 0) {
-      olState* state = (olState*)mOLStateStack.ElementAt(mOLStateStack.Count() -1);
-      mOLStateStack.RemoveElementAt(mOLStateStack.Count() -1);
+    if (!mOLStateStack.IsEmpty()) {
+      olState* state = mOLStateStack.ElementAt(mOLStateStack.Length() -1);
+      mOLStateStack.RemoveElementAt(mOLStateStack.Length() -1);
       delete state;
     }
   }
   
   nsIParserService* parserService = nsContentUtils::GetParserService();
 
   if (parserService && (name != nsGkAtoms::style)) {
     PRBool isContainer;
@@ -1238,22 +1236,22 @@ nsHTMLContentSerializer::SerializeLIValu
   // It may not be the first LI child of OL but it's first in the selected range.
   // Note that we get into this condition only once per a OL.
   PRBool found = PR_FALSE;
   nsCOMPtr<nsIDOMNode> currNode = do_QueryInterface(aElement);
   nsAutoString valueStr;
   PRInt32 offset = 0;
   olState defaultOLState(0, PR_FALSE);
   olState* state = nsnull;
-  if (mOLStateStack.Count() > 0) 
-    state = (olState*)mOLStateStack.ElementAt(mOLStateStack.Count()-1);
-  /* Though we should never reach to a "state" as null or mOLStateStack.Count() == 0 
+  if (!mOLStateStack.IsEmpty())
+    state = mOLStateStack.ElementAt(mOLStateStack.Length()-1);
+  /* Though we should never reach to a "state" as null or mOLStateStack.IsEmpty()
   at this point as all LI are supposed to be inside some OL and OL tag should have 
   pushed a state to the olStateStack.*/
-  if (!state || mOLStateStack.Count() == 0)
+  if (!state || mOLStateStack.IsEmpty())
     state = &defaultOLState;
   PRInt32 startVal = state->startVal;
   state->isFirstListItem = PR_FALSE;
   // Traverse previous siblings until we find one with "value" attribute.
   // offset keeps track of how many previous siblings we had tocurrNode traverse.
   while (currNode && !found) {
     nsCOMPtr<nsIDOMElement> currElement = do_QueryInterface(currNode);
     // currElement may be null if it were a text node.
@@ -1310,18 +1308,18 @@ nsHTMLContentSerializer::IsFirstChildOfO
       parentNode->GetNodeName(parentName);
     else
       return PR_FALSE;
   }
   
   if (parentName.LowerCaseEqualsLiteral("ol")) {
     olState defaultOLState(0, PR_FALSE);
     olState* state = nsnull;
-    if (mOLStateStack.Count() > 0) 
-      state = (olState*)mOLStateStack.ElementAt(mOLStateStack.Count()-1);
+    if (!mOLStateStack.IsEmpty())
+      state = mOLStateStack.ElementAt(mOLStateStack.Length()-1);
     /* Though we should never reach to a "state" as null at this point as 
     all LI are supposed to be inside some OL and OL tag should have pushed
     a state to the mOLStateStack.*/
     if (!state)
       state = &defaultOLState;
     
     if (state->isFirstListItem)
       return PR_TRUE;
--- a/content/base/src/nsHTMLContentSerializer.h
+++ b/content/base/src/nsHTMLContentSerializer.h
@@ -43,16 +43,17 @@
  */
 
 #ifndef nsHTMLContentSerializer_h__
 #define nsHTMLContentSerializer_h__
 
 #include "nsXMLContentSerializer.h"
 #include "nsIEntityConverter.h"
 #include "nsString.h"
+#include "nsTArray.h"
 
 class nsIContent;
 class nsIAtom;
 
 class nsHTMLContentSerializer : public nsXMLContentSerializer {
  public:
   nsHTMLContentSerializer();
   virtual ~nsHTMLContentSerializer();
@@ -163,15 +164,16 @@ class nsHTMLContentSerializer : public n
   struct olState {
     olState(PRInt32 aStart, PRBool aIsFirst):startVal(aStart),isFirstListItem(aIsFirst)
     {
     }
     PRInt32 startVal;
     PRBool isFirstListItem;
   };
 
-  nsAutoVoidArray   mOLStateStack;// Stack to store one olState struct per <OL>.
+  // Stack to store one olState struct per <OL>.
+  nsAutoTArray<olState*, 8> mOLStateStack;
 };
 
 nsresult
 NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer);
 
 #endif
--- a/content/base/src/nsPlainTextSerializer.cpp
+++ b/content/base/src/nsPlainTextSerializer.cpp
@@ -230,50 +230,50 @@ nsPlainTextSerializer::Init(PRUint32 aFl
   else {
     mFlags |= nsIDocumentEncoder::OutputNoFramesContent;
   }
 
   return NS_OK;
 }
 
 PRBool
-nsPlainTextSerializer::GetLastBool(const nsVoidArray& aStack)
+nsPlainTextSerializer::GetLastBool(const nsTArray<PRPackedBool>& aStack)
 {
-  PRUint32 size = aStack.Count();
+  PRUint32 size = aStack.Length();
   if (size == 0) {
     return PR_FALSE;
   }
-  return (aStack.ElementAt(size-1) != reinterpret_cast<void*>(PR_FALSE));
+  return aStack.ElementAt(size-1);
 }
 
 void
-nsPlainTextSerializer::SetLastBool(nsVoidArray& aStack, PRBool aValue)
+nsPlainTextSerializer::SetLastBool(nsTArray<PRPackedBool>& aStack, PRBool aValue)
 {
-  PRUint32 size = aStack.Count();
+  PRUint32 size = aStack.Length();
   if (size > 0) {
-    aStack.ReplaceElementAt(reinterpret_cast<void*>(aValue), size-1);
+    aStack.ElementAt(size-1) = aValue;
   }
   else {
     NS_ERROR("There is no \"Last\" value");
   }
 }
 
 void
-nsPlainTextSerializer::PushBool(nsVoidArray& aStack, PRBool aValue)
+nsPlainTextSerializer::PushBool(nsTArray<PRPackedBool>& aStack, PRBool aValue)
 {
-    aStack.AppendElement(reinterpret_cast<void*>(aValue));
+    aStack.AppendElement(PRPackedBool(aValue));
 }
 
 PRBool
-nsPlainTextSerializer::PopBool(nsVoidArray& aStack)
+nsPlainTextSerializer::PopBool(nsTArray<PRPackedBool>& aStack)
 {
   PRBool returnValue = PR_FALSE;
-  PRUint32 size = aStack.Count();
+  PRUint32 size = aStack.Length();
   if (size > 0) {
-    returnValue = (aStack.ElementAt(size-1) != reinterpret_cast<void*>(PR_FALSE));
+    returnValue = aStack.ElementAt(size-1);
     aStack.RemoveElementAt(size-1);
   }
   return returnValue;
 }
 
 NS_IMETHODIMP
 nsPlainTextSerializer::Initialize(nsAString* aOutString,
                                   PRUint32 aFlags, PRUint32 aWrapCol)
@@ -676,17 +676,17 @@ nsPlainTextSerializer::DoOpenContainer(c
 
     // To make the separation between cells most obvious and
     // importable, we use a TAB.
     if (GetLastBool(mHasWrittenCellsForRow)) {
       // Bypass |Write| so that the TAB isn't compressed away.
       AddToLine(NS_LITERAL_STRING("\t").get(), 1);
       mInWhitespace = PR_TRUE;
     }
-    else if (mHasWrittenCellsForRow.Count() == 0) {
+    else if (mHasWrittenCellsForRow.IsEmpty()) {
       // We don't always see a <tr> (nor a <table>) before the <td> if we're
       // copying part of a table
       PushBool(mHasWrittenCellsForRow, PR_TRUE); // will never be popped
     }
     else {
       SetLastBool(mHasWrittenCellsForRow, PR_TRUE);
     }
   }
--- a/content/base/src/nsPlainTextSerializer.h
+++ b/content/base/src/nsPlainTextSerializer.h
@@ -49,17 +49,17 @@
 #include "nsHTMLTags.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsILineBreaker.h"
 #include "nsIContent.h"
 #include "nsIAtom.h"
 #include "nsIHTMLToTextSink.h"
 #include "nsIDocumentEncoder.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
 
 class nsPlainTextSerializer : public nsIContentSerializer,
                               public nsIHTMLContentSink,
                               public nsIHTMLToTextSink
 {
 public:
   nsPlainTextSerializer();
@@ -159,20 +159,20 @@ protected:
   }
 
   inline PRBool DoOutput()
   {
     return mHeadLevel == 0;
   }
 
   // Stack handling functions
-  PRBool GetLastBool(const nsVoidArray& aStack);
-  void SetLastBool(nsVoidArray& aStack, PRBool aValue);
-  void PushBool(nsVoidArray& aStack, PRBool aValue);
-  PRBool PopBool(nsVoidArray& aStack);
+  PRBool GetLastBool(const nsTArray<PRPackedBool>& aStack);
+  void SetLastBool(nsTArray<PRPackedBool>& aStack, PRBool aValue);
+  void PushBool(nsTArray<PRPackedBool>& aStack, PRBool aValue);
+  PRBool PopBool(nsTArray<PRPackedBool>& aStack);
   
 protected:
   nsString         mCurrentLine;
   PRUint32         mHeadLevel;
   PRPackedBool     mAtFirstColumn;
 
   // Handling of quoted text (for mail):
   // Quotes need to be wrapped differently from non-quoted text,
@@ -236,21 +236,21 @@ protected:
                                           Number of previous headers of
                                           the same depth and in the same
                                           section.
                                           mHeaderCounter[1] for <h1> etc. */
 
   nsCOMPtr<nsIContent> mContent;
 
   // For handling table rows
-  nsAutoVoidArray mHasWrittenCellsForRow; // really an array of bools
+  nsAutoTArray<PRPackedBool, 8> mHasWrittenCellsForRow;
   
   // Values gotten in OpenContainer that is (also) needed in CloseContainer
-  nsAutoVoidArray     mCurrentNodeIsConverted; // really an array of bools
-  nsAutoVoidArray     mIsInCiteBlockquote; // really an array of bools
+  nsAutoTArray<PRPackedBool, 8> mCurrentNodeIsConverted;
+  nsAutoTArray<PRPackedBool, 8> mIsInCiteBlockquote;
 
   // The output data
   nsAString*            mOutputString;
 
   // The tag stack: the stack of tags we're operating on, so we can nest:
   nsHTMLTag       *mTagStack;
   PRUint32         mTagStackIndex;
 
--- a/content/base/src/nsRange.h
+++ b/content/base/src/nsRange.h
@@ -48,18 +48,16 @@
 #include "nsIDOMNSRange.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMDocumentFragment.h"
 #include "nsIContent.h"
 #include "nsIDOMNode.h"
 #include "prmon.h"
 #include "nsStubMutationObserver.h"
 
-class nsVoidArray;
-
 // -------------------------------------------------------------------------------
 
 class nsRangeUtils : public nsIRangeUtils
 {
 public:
   NS_DECL_ISUPPORTS
 
   // nsIRangeUtils interface
--- a/content/base/src/nsScriptEventManager.h
+++ b/content/base/src/nsScriptEventManager.h
@@ -39,17 +39,16 @@
 /*
  * Class that allows finding an event handler <script> node (one using
  * FOR="....") for a given event and dispatching the event to that
  * node.
  */
 
 #include "nsCOMPtr.h"
 #include "nsAString.h"
-#include "nsVoidArray.h"
 
 #include "nsIScriptEventManager.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMDocument.h"
 
 class nsScriptEventManager : public nsIScriptEventManager
 {
 
--- a/content/base/src/nsStyleLinkElement.cpp
+++ b/content/base/src/nsStyleLinkElement.cpp
@@ -52,17 +52,16 @@
 #include "nsIDOMComment.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMStyleSheet.h"
 #include "nsIDOMText.h"
 #include "nsIUnicharInputStream.h"
 #include "nsISimpleUnicharStreamFactory.h"
 #include "nsNetUtil.h"
 #include "nsUnicharUtils.h"
-#include "nsVoidArray.h"
 #include "nsCRT.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsUnicharInputStream.h"
 #include "nsContentUtils.h"
 
 nsStyleLinkElement::nsStyleLinkElement()
   : mDontLoadStyle(PR_FALSE)
   , mUpdatesEnabled(PR_TRUE)
--- a/content/base/src/nsTreeWalker.cpp
+++ b/content/base/src/nsTreeWalker.cpp
@@ -553,18 +553,17 @@ nsTreeWalker::ChildOf(nsINode* aNode,
  * @param aIndexPos position in mPossibleIndexes that contains the possible.
  *                  index
  * @returns         resulting index
  */
 PRInt32 nsTreeWalker::IndexOf(nsINode* aParent,
                               nsINode* aChild,
                               PRInt32 aIndexPos)
 {
-    if (aIndexPos >= 0 && aIndexPos < mPossibleIndexes.Count()) {
-        PRInt32 possibleIndex =
-            NS_PTR_TO_INT32(mPossibleIndexes.FastElementAt(aIndexPos));
+    if (aIndexPos >= 0 && aIndexPos < PRInt32(mPossibleIndexes.Length())) {
+        PRInt32 possibleIndex = mPossibleIndexes.ElementAt(aIndexPos);
         if (aChild == aParent->GetChildAt(possibleIndex)) {
             return possibleIndex;
         }
     }
 
     return aParent->IndexOf(aChild);
 }
--- a/content/base/src/nsTreeWalker.h
+++ b/content/base/src/nsTreeWalker.h
@@ -42,17 +42,17 @@
  */
 
 #ifndef nsTreeWalker_h___
 #define nsTreeWalker_h___
 
 #include "nsIDOMTreeWalker.h"
 #include "nsTraversal.h"
 #include "nsCOMPtr.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsINode;
 class nsIDOMNode;
 class nsIDOMNodeFilter;
 
 class nsTreeWalker : public nsIDOMTreeWalker, public nsTraversal
 {
@@ -69,19 +69,18 @@ public:
     NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeWalker)
 
 private:
     nsCOMPtr<nsINode> mCurrentNode;
     
     /*
      * Array with all child indexes up the tree. This should only be
      * considered a hint and the value could be wrong.
-     * The array contains casted PRInt32's
      */
-    nsAutoVoidArray mPossibleIndexes;
+    nsAutoTArray<PRInt32, 8> mPossibleIndexes;
     
     /*
      * Position of mCurrentNode in mPossibleIndexes
      */
     PRInt32 mPossibleIndexesPos;
     
     /*
      * Finds the first child of aNode and returns it. If a child is
@@ -163,16 +162,17 @@ private:
     /*
      * Sets the child index at the specified level. It doesn't matter if this
      * fails since mPossibleIndexes should only be considered a hint
      * @param aIndexPos   position in mPossibleIndexes to set
      * @param aChildIndex child index at specified position
      */
     void SetChildIndex(PRInt32 aIndexPos, PRInt32 aChildIndex)
     {
-        if (aIndexPos != -1)
-            mPossibleIndexes.ReplaceElementAt(NS_INT32_TO_PTR(aChildIndex),
-                                              aIndexPos);
+        if (aIndexPos > 0) {
+            mPossibleIndexes.EnsureLengthAtLeast(aIndexPos+1);
+            mPossibleIndexes.ElementAt(aIndexPos) = aChildIndex;
+        }
     }
 };
 
 #endif
 
--- a/content/base/src/nsXMLContentSerializer.cpp
+++ b/content/base/src/nsXMLContentSerializer.cpp
@@ -59,21 +59,21 @@
 #include "nsTextFragment.h"
 #include "nsString.h"
 #include "prprf.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 #include "nsContentUtils.h"
 #include "nsAttrName.h"
 
-typedef struct {
+struct NameSpaceDecl {
   nsString mPrefix;
   nsString mURI;
   nsIDOMElement* mOwner;
-} NameSpaceDecl;
+};
 
 nsresult NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer)
 {
   nsXMLContentSerializer* it = new nsXMLContentSerializer();
   if (!it) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
@@ -341,28 +341,28 @@ nsXMLContentSerializer::PushNameSpaceDec
   if (!decl) return NS_ERROR_OUT_OF_MEMORY;
 
   decl->mPrefix.Assign(aPrefix);
   decl->mURI.Assign(aURI);
   // Don't addref - this weak reference will be removed when
   // we pop the stack
   decl->mOwner = aOwner;
 
-  mNameSpaceStack.AppendElement((void*)decl);
+  mNameSpaceStack.AppendElement(decl);
   return NS_OK;
 }
 
 void
 nsXMLContentSerializer::PopNameSpaceDeclsFor(nsIDOMElement* aOwner)
 {
   PRInt32 index, count;
 
-  count = mNameSpaceStack.Count();
+  count = mNameSpaceStack.Length();
   for (index = count - 1; index >= 0; index--) {
-    NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index);
+    NameSpaceDecl* decl = mNameSpaceStack.ElementAt(index);
     if (decl->mOwner != aOwner) {
       break;
     }
     mNameSpaceStack.RemoveElementAt(index);
     delete decl;
   }
 }
 
@@ -406,20 +406,20 @@ nsXMLContentSerializer::ConfirmPrefix(ns
   nsAutoString closestURIMatch;
   PRBool uriMatch = PR_FALSE;
 
   // Also keep track of whether we've seen aPrefix already.  If we have, that
   // means that it's already bound to a URI different from aURI, so even if we
   // later (so in a more outer scope) see it bound to aURI we can't reuse it.
   PRBool haveSeenOurPrefix = PR_FALSE;
 
-  PRInt32 count = mNameSpaceStack.Count();
+  PRInt32 count = mNameSpaceStack.Length();
   PRInt32 index = count - 1;
   while (index >= 0) {
-    NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index);
+    NameSpaceDecl* decl = mNameSpaceStack.ElementAt(index);
     // Check if we've found a prefix match
     if (aPrefix.Equals(decl->mPrefix)) {
 
       // If the URIs match and aPrefix is not bound to any other URI, we can
       // use aPrefix
       if (!haveSeenOurPrefix && aURI.Equals(decl->mURI)) {
         // Just use our uriMatch stuff.  That will deal with an empty aPrefix
         // the right way.  We can break out of the loop now, though.
@@ -459,18 +459,17 @@ nsXMLContentSerializer::ConfirmPrefix(ns
     
     // If we've found a URI match, then record the first one
     if (!uriMatch && aURI.Equals(decl->mURI)) {
       // Need to check that decl->mPrefix is not declared anywhere closer to
       // us.  If it is, we can't use it.
       PRBool prefixOK = PR_TRUE;
       PRInt32 index2;
       for (index2 = count-1; index2 > index && prefixOK; --index2) {
-        NameSpaceDecl* decl2 =
-          (NameSpaceDecl*)mNameSpaceStack.ElementAt(index2);
+        NameSpaceDecl* decl2 = mNameSpaceStack.ElementAt(index2);
         prefixOK = (decl2->mPrefix != decl->mPrefix);
       }
       
       if (prefixOK) {
         uriMatch = PR_TRUE;
         closestURIMatch.Assign(decl->mPrefix);
       }
     }
--- a/content/base/src/nsXMLContentSerializer.h
+++ b/content/base/src/nsXMLContentSerializer.h
@@ -42,20 +42,22 @@
  */
 
 #ifndef nsXMLContentSerializer_h__
 #define nsXMLContentSerializer_h__
 
 #include "nsIContentSerializer.h"
 #include "nsISupportsUtils.h"
 #include "nsCOMPtr.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
+#include "nsString.h"
 
 class nsIDOMNode;
 class nsIAtom;
+struct NameSpaceDecl;
 
 class nsXMLContentSerializer : public nsIContentSerializer {
  public:
   nsXMLContentSerializer();
   virtual ~nsXMLContentSerializer();
 
   NS_DECL_ISUPPORTS
 
@@ -151,17 +153,17 @@ class nsXMLContentSerializer : public ns
                                        nsAString& aOutputStr);
 
   // Functions to check for newlines that needs to be added between nodes in
   // the root of a document.
   void MaybeAddNewline(nsAString& aStr);
   void MaybeFlagNewline(nsIDOMNode* aNode);
 
   PRInt32 mPrefixIndex;
-  nsVoidArray mNameSpaceStack;
+  nsTArray<NameSpaceDecl*> mNameSpaceStack;
 
   // nsIDocumentEncoder flags
   PRUint32  mFlags;
 
   // characters to use for line break
   nsString  mLineBreak;
 
   // The charset that was passed to Init()
--- a/content/base/src/nsXMLNameSpaceMap.cpp
+++ b/content/base/src/nsXMLNameSpaceMap.cpp
@@ -77,36 +77,35 @@ nsXMLNameSpaceMap::Create()
 nsXMLNameSpaceMap::nsXMLNameSpaceMap()
   : mNameSpaces(4)
 {
 }
 
 nsresult
 nsXMLNameSpaceMap::AddPrefix(nsIAtom *aPrefix, PRInt32 aNameSpaceID)
 {
-  PRInt32 count = mNameSpaces.Count();
+  PRUint32 count = mNameSpaces.Length();
   nsNameSpaceEntry *foundEntry = nsnull;
 
-  for (PRInt32 i = 0; i < count; ++i) {
-    nsNameSpaceEntry *entry = static_cast<nsNameSpaceEntry*>
-                                         (mNameSpaces.FastElementAt(i));
+  for (PRUint32 i = 0; i < count; ++i) {
+    nsNameSpaceEntry *entry = mNameSpaces.ElementAt(i);
 
     NS_ASSERTION(entry, "null entry in namespace map!");
 
     if (entry->prefix == aPrefix) {
       foundEntry = entry;
       break;
     }
   }
 
   if (!foundEntry) {
     foundEntry = new nsNameSpaceEntry(aPrefix);
     NS_ENSURE_TRUE(foundEntry, NS_ERROR_OUT_OF_MEMORY);
 
-    if (!mNameSpaces.AppendElement(foundEntry)) {
+    if (mNameSpaces.AppendElement(foundEntry) == nsnull) {
       delete foundEntry;
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   foundEntry->nameSpaceID = aNameSpaceID;
   return NS_OK;
 }
@@ -121,39 +120,37 @@ nsXMLNameSpaceMap::AddPrefix(nsIAtom *aP
   NS_ENSURE_SUCCESS(rv, rv);
 
   return AddPrefix(aPrefix, id);
 }
 
 void
 nsXMLNameSpaceMap::RemovePrefix(nsIAtom *aPrefix)
 {
-  PRInt32 count = mNameSpaces.Count();
+  PRUint32 count = mNameSpaces.Length();
 
-  for (PRInt32 i = 0; i < count; ++i) {
-    nsNameSpaceEntry *entry = static_cast<nsNameSpaceEntry*>
-                                         (mNameSpaces.FastElementAt(i));
+  for (PRUint32 i = 0; i < count; ++i) {
+    nsNameSpaceEntry *entry = mNameSpaces.ElementAt(i);
 
     NS_ASSERTION(entry, "null entry in namespace map!");
 
     if (entry->prefix == aPrefix) {
       mNameSpaces.RemoveElementAt(i);
       return;
     }
   }
 }
 
 PRInt32
 nsXMLNameSpaceMap::FindNameSpaceID(nsIAtom *aPrefix) const
 {
-  PRInt32 count = mNameSpaces.Count();
+  PRUint32 count = mNameSpaces.Length();
 
-  for (PRInt32 i = 0; i < count; ++i) {
-    nsNameSpaceEntry *entry = static_cast<nsNameSpaceEntry*>
-                                         (mNameSpaces.FastElementAt(i));
+  for (PRUint32 i = 0; i < count; ++i) {
+    nsNameSpaceEntry *entry = mNameSpaces.ElementAt(i);
 
     NS_ASSERTION(entry, "null entry in namespace map!");
 
     if (entry->prefix == aPrefix) {
       return entry->nameSpaceID;
     }
   }
 
@@ -161,35 +158,31 @@ nsXMLNameSpaceMap::FindNameSpaceID(nsIAt
   // was specified and we didn't find it, we return an error.
 
   return aPrefix ? kNameSpaceID_Unknown : kNameSpaceID_None;
 }
 
 nsIAtom*
 nsXMLNameSpaceMap::FindPrefix(PRInt32 aNameSpaceID) const
 {
-  PRInt32 count = mNameSpaces.Count();
+  PRUint32 count = mNameSpaces.Length();
 
-  for (PRInt32 i = 0; i < count; ++i) {
-    nsNameSpaceEntry *entry = static_cast<nsNameSpaceEntry*>
-                                         (mNameSpaces.FastElementAt(i));
+  for (PRUint32 i = 0; i < count; ++i) {
+    nsNameSpaceEntry *entry = mNameSpaces.ElementAt(i);
 
     NS_ASSERTION(entry, "null entry in namespace map!");
 
     if (entry->nameSpaceID == aNameSpaceID) {
       return entry->prefix;
     }
   }
 
   return nsnull;
 }
 
-static PRBool DeleteEntry(void *aElement, void *aData)
-{
-  delete static_cast<nsNameSpaceEntry*>(aElement);
-  return PR_TRUE;
-}
-
 void
 nsXMLNameSpaceMap::Clear()
 {
-  mNameSpaces.EnumerateForwards(DeleteEntry, nsnull);
+  for (PRUint32 i = 0, len = mNameSpaces.Length(); i < len; ++i) {
+    delete mNameSpaces[i];
+  }
+  mNameSpaces.Clear();
 }
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -89,17 +89,16 @@
 #include "nsIHttpChannel.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsStubDocumentObserver.h"
 #include "nsIHTMLDocument.h"
 #include "nsINameSpaceManager.h"
 #include "nsIDOMHTMLMapElement.h"
 #include "nsICookieService.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #include "nsTextFragment.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptGlobalObjectOwner.h"
 
 #include "nsIParserService.h"
@@ -242,17 +241,17 @@ protected:
 
   nsGenericHTMLElement* mRoot;
   nsGenericHTMLElement* mBody;
   nsRefPtr<nsGenericHTMLElement> mFrameset;
   nsGenericHTMLElement* mHead;
 
   nsRefPtr<nsGenericHTMLElement> mCurrentForm;
 
-  nsAutoVoidArray mContextStack;
+  nsAutoTArray<SinkContext*, 8> mContextStack;
   SinkContext* mCurrentContext;
   SinkContext* mHeadContext;
   PRInt32 mNumOpenIFRAMES;
 
   nsCOMPtr<nsIURI> mBaseHref;
   nsCOMPtr<nsIAtom> mBaseTarget;
 
   // depth of containment within <noembed>, <noframes> etc
@@ -1545,26 +1544,26 @@ HTMLContentSink::~HTMLContentSink()
   NS_IF_RELEASE(mRoot);
 
   NS_IF_RELEASE(mHTMLDocument);
 
   if (mNotificationTimer) {
     mNotificationTimer->Cancel();
   }
 
-  PRInt32 numContexts = mContextStack.Count();
+  PRInt32 numContexts = mContextStack.Length();
 
   if (mCurrentContext == mHeadContext && numContexts > 0) {
     // Pop off the second html context if it's not done earlier
     mContextStack.RemoveElementAt(--numContexts);
   }
 
   PRInt32 i;
   for (i = 0; i < numContexts; i++) {
-    SinkContext* sc = (SinkContext*)mContextStack.ElementAt(i);
+    SinkContext* sc = mContextStack.ElementAt(i);
     if (sc) {
       sc->End();
       if (sc == mCurrentContext) {
         mCurrentContext = nsnull;
       }
 
       delete sc;
     }
@@ -1918,18 +1917,18 @@ HTMLContentSink::BeginContext(PRInt32 aP
 
 NS_IMETHODIMP
 HTMLContentSink::EndContext(PRInt32 aPosition)
 {
   MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::EndContext()\n"));
   MOZ_TIMER_START(mWatch);
   NS_PRECONDITION(mCurrentContext && aPosition > -1, "non-existing context");
 
-  PRInt32 n = mContextStack.Count() - 1;
-  SinkContext* sc = (SinkContext*) mContextStack.ElementAt(n);
+  PRUint32 n = mContextStack.Length() - 1;
+  SinkContext* sc = mContextStack.ElementAt(n);
 
   const SinkContext::Node &bottom = mCurrentContext->mStack[0];
   
   NS_ASSERTION(sc->mStack[aPosition].mType == bottom.mType,
                "ending a wrong context");
 
   mCurrentContext->FlushTextAndRelease();
   
@@ -1980,20 +1979,20 @@ HTMLContentSink::CloseHTML()
   MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseHTML()\n"));
   MOZ_TIMER_START(mWatch);
   SINK_TRACE_NODE(SINK_TRACE_CALLS,
                  "HTMLContentSink::CloseHTML", 
                  eHTMLTag_html, 0, this);
 
   if (mHeadContext) {
     if (mCurrentContext == mHeadContext) {
-      PRInt32 numContexts = mContextStack.Count();
+      PRUint32 numContexts = mContextStack.Length();
 
       // Pop off the second html context if it's not done earlier
-      mCurrentContext = (SinkContext*)mContextStack.ElementAt(--numContexts);
+      mCurrentContext = mContextStack.ElementAt(--numContexts);
       mContextStack.RemoveElementAt(numContexts);
     }
 
     NS_ASSERTION(mHeadContext->mTextLength == 0, "Losing text");
 
     mHeadContext->End();
 
     delete mHeadContext;
@@ -2827,21 +2826,22 @@ HTMLContentSink::CloseHeadContext()
 {
   if (mCurrentContext) {
     if (!mCurrentContext->IsCurrentContainer(eHTMLTag_head))
       return;
 
     mCurrentContext->FlushTextAndRelease();
   }
 
-  NS_ASSERTION(mContextStack.Count() > 0, "Stack should not be empty");
-  
-  PRInt32 n = mContextStack.Count() - 1;
-  mCurrentContext = (SinkContext*) mContextStack.ElementAt(n);
-  mContextStack.RemoveElementAt(n);
+  if (!mContextStack.IsEmpty())
+  {
+    PRUint32 n = mContextStack.Length() - 1;
+    mCurrentContext = mContextStack.ElementAt(n);
+    mContextStack.RemoveElementAt(n);
+  }
 }
 
 void
 HTMLContentSink::ProcessBASEElement(nsGenericHTMLElement* aElement)
 {
   // href attribute
   nsAutoString attrValue;
   if (aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, attrValue)) {
@@ -3065,19 +3065,19 @@ HTMLContentSink::IsMonolithicContainer(n
   }
 
   return PR_FALSE;
 }
 
 void
 HTMLContentSink::UpdateChildCounts()
 {
-  PRInt32 numContexts = mContextStack.Count();
-  for (PRInt32 i = 0; i < numContexts; i++) {
-    SinkContext* sc = (SinkContext*)mContextStack.ElementAt(i);
+  PRUint32 numContexts = mContextStack.Length();
+  for (PRUint32 i = 0; i < numContexts; i++) {
+    SinkContext* sc = mContextStack.ElementAt(i);
 
     sc->UpdateChildCounts();
   }
 
   mCurrentContext->UpdateChildCounts();
 }
 
 void
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -2078,19 +2078,17 @@ nsHTMLDocument::Close()
     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
   }
 
   nsresult rv = NS_OK;
 
   if (mParser && mWriteState == eDocumentOpened) {
     mPendingScripts.RemoveElement(GenerateParserKey());
 
-    mWriteState = mPendingScripts.Count() == 0
-                  ? eDocumentClosed
-                  : ePendingClose;
+    mWriteState = mPendingScripts.IsEmpty() ? eDocumentClosed : ePendingClose;
 
     ++mWriteLevel;
     rv = mParser->Parse(EmptyString(), mParser->GetRootContextKey(),
                         mContentType, PR_TRUE);
     --mWriteLevel;
 
     // XXX Make sure that all the document.written content is
     // reflowed.  We should remove this call once we change
@@ -2145,17 +2143,17 @@ nsHTMLDocument::WriteCommon(const nsAStr
     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
   }
 
   nsresult rv = NS_OK;
 
   void *key = GenerateParserKey();
   if (mWriteState == eDocumentClosed ||
       (mWriteState == ePendingClose &&
-       mPendingScripts.IndexOf(key) == kNotFound)) {
+       !mPendingScripts.Contains(key))) {
     mWriteState = eDocumentClosed;
     mParser->Terminate();
     NS_ASSERTION(!mParser, "mParser should have been null'd out");
   }
 
   if (!mParser) {
     rv = Open();
 
@@ -2365,17 +2363,17 @@ nsHTMLDocument::ScriptLoading(nsIScriptE
 void
 nsHTMLDocument::ScriptExecuted(nsIScriptElement *aScript)
 {
   if (mWriteState == eNotWriting) {
     return;
   }
 
   mPendingScripts.RemoveElement(aScript);
-  if (mPendingScripts.Count() == 0 && mWriteState == ePendingClose) {
+  if (mPendingScripts.IsEmpty() && mWriteState == ePendingClose) {
     // The last pending script just finished, terminate our parser now.
     mWriteState = eDocumentClosed;
   }
 }
 
 void
 nsHTMLDocument::AddedForm()
 {
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -42,16 +42,17 @@
 #include "nsIHTMLDocument.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMNSHTMLDocument.h"
 #include "nsIDOMHTMLBodyElement.h"
 #include "nsIDOMHTMLMapElement.h"
 #include "nsIDOMHTMLCollection.h"
 #include "nsIScriptElement.h"
 #include "jsapi.h"
+#include "nsTArray.h"
 
 #include "pldhash.h"
 #include "nsIHttpChannel.h"
 #include "nsHTMLStyleSheet.h"
 
 // Document.Write() related
 #include "nsIWyciwygChannel.h"
 #include "nsILoadGroup.h"
@@ -337,17 +338,17 @@ protected:
   } mWriteState;
 
   // Tracks if we are currently processing any document.write calls (either
   // implicit or explicit). Note that if a write call writes out something which
   // would block the parser, then mWriteLevel will be incorrect until the parser
   // finishes processing that script.
   PRUint32 mWriteLevel;
 
-  nsSmallVoidArray mPendingScripts;
+  nsAutoTArray<nsIScriptElement*, 1> mPendingScripts;
 
   // Load flags of the document's channel
   PRUint32 mLoadFlags;
 
   PRPackedBool mIsFrameset;
 
   PRPackedBool mTooDeepWriteRecursion;
 
--- a/content/html/document/src/nsHTMLFragmentContentSink.cpp
+++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp
@@ -44,17 +44,17 @@
 #include "nsIParserService.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLTokens.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMText.h"
 #include "nsIDOMComment.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIDOMDocumentFragment.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsINameSpaceManager.h"
 #include "nsIDocument.h"
 #include "nsINodeInfo.h"
 #include "prmem.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsContentUtils.h"
 #include "nsEscape.h"
@@ -145,17 +145,17 @@ public:
   PRPackedBool mProcessing;
   PRPackedBool mSeenBody;
   PRPackedBool mIgnoreContainer;
   PRPackedBool mIgnoreNextCloseHead;
 
   nsCOMPtr<nsIContent> mRoot;
   nsCOMPtr<nsIParser> mParser;
 
-  nsVoidArray* mContentStack;
+  nsTArray<nsIContent*>* mContentStack;
 
   PRUnichar* mText;
   PRInt32 mTextLength;
   PRInt32 mTextSize;
 
   nsCOMPtr<nsIURI> mBaseHref;
   nsCOMPtr<nsIAtom> mBaseTarget;
 
@@ -205,19 +205,19 @@ nsHTMLFragmentContentSink::nsHTMLFragmen
 
 nsHTMLFragmentContentSink::~nsHTMLFragmentContentSink()
 {
   // Should probably flush the text buffer here, just to make sure:
   //FlushText();
 
   if (nsnull != mContentStack) {
     // there shouldn't be anything here except in an error condition
-    PRInt32 indx = mContentStack->Count();
+    PRInt32 indx = mContentStack->Length();
     while (0 < indx--) {
-      nsIContent* content = (nsIContent*)mContentStack->ElementAt(indx);
+      nsIContent* content = mContentStack->ElementAt(indx);
       NS_RELEASE(content);
     }
     delete mContentStack;
   }
 
   PR_FREEIF(mText);
 
   PRUint32 i;
@@ -675,42 +675,42 @@ nsHTMLFragmentContentSink::IgnoreFirstCo
   mIgnoreContainer = PR_TRUE;
   return NS_OK;
 }
 
 nsIContent*
 nsHTMLFragmentContentSink::GetCurrentContent()
 {
   if (nsnull != mContentStack) {
-    PRInt32 indx = mContentStack->Count() - 1;
+    PRInt32 indx = mContentStack->Length() - 1;
     if (indx >= 0)
-      return (nsIContent *)mContentStack->ElementAt(indx);
+      return mContentStack->ElementAt(indx);
   }
   return nsnull;
 }
 
 PRInt32
 nsHTMLFragmentContentSink::PushContent(nsIContent *aContent)
 {
   if (nsnull == mContentStack) {
-    mContentStack = new nsVoidArray();
+    mContentStack = new nsTArray<nsIContent*>();
   }
 
-  mContentStack->AppendElement((void *)aContent);
-  return mContentStack->Count();
+  mContentStack->AppendElement(aContent);
+  return mContentStack->Length();
 }
 
 nsIContent*
 nsHTMLFragmentContentSink::PopContent()
 {
   nsIContent* content = nsnull;
   if (nsnull != mContentStack) {
-    PRInt32 indx = mContentStack->Count() - 1;
+    PRInt32 indx = mContentStack->Length() - 1;
     if (indx >= 0) {
-      content = (nsIContent *)mContentStack->ElementAt(indx);
+      content = mContentStack->ElementAt(indx);
       mContentStack->RemoveElementAt(indx);
     }
   }
   return content;
 }
 
 #define NS_ACCUMULATION_BUFFER_SIZE 4096
 
--- a/content/svg/content/src/nsSVGDataParser.h
+++ b/content/svg/content/src/nsSVGDataParser.h
@@ -34,17 +34,16 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_SVGDATAPARSER_H__
 #define __NS_SVGDATAPARSER_H__
 
 #include "nsCOMPtr.h"
-#include "nsVoidArray.h"
 
 //----------------------------------------------------------------------
 // helper macros
 #define ENSURE_MATCHED(exp) { nsresult rv = exp; if (NS_FAILED(rv)) return rv; }
 
 ////////////////////////////////////////////////////////////////////////
 // nsSVGDataParser: a simple abstract class for parsing values
 // for path and transform values.
--- a/content/svg/content/src/nsSVGLengthList.cpp
+++ b/content/svg/content/src/nsSVGLengthList.cpp
@@ -35,17 +35,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsSVGLengthList.h"
 #include "nsSVGLength.h"
 #include "nsSVGValue.h"
 #include "nsWeakReference.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsDOMError.h"
 #include "nsReadableUtils.h"
 #include "nsSVGSVGElement.h"
 #include "nsCRT.h"
 #include "nsISVGValueUtils.h"
 #include "nsContentUtils.h"
 
 ////////////////////////////////////////////////////////////////////////
@@ -88,17 +88,17 @@ protected:
   // implementation helpers:
   nsISVGLength* ElementAt(PRInt32 index);
   void AppendElement(nsISVGLength* aElement);
   void RemoveElementAt(PRInt32 index);
   void InsertElementAt(nsISVGLength* aElement, PRInt32 index);
   
   void ReleaseLengths();
   
-  nsAutoVoidArray mLengths;
+  nsAutoTArray<nsISVGLength*, 1> mLengths;
   nsWeakPtr mContext;  // needs to be weak to avoid reference loop
   PRUint8 mCtxType;
 };
 
 
 //----------------------------------------------------------------------
 // Implementation
 
@@ -163,21 +163,21 @@ nsSVGLengthList::SetValueString(const ns
   return rv;
 }
 
 NS_IMETHODIMP
 nsSVGLengthList::GetValueString(nsAString& aValue)
 {
   aValue.Truncate();
 
-  PRInt32 count = mLengths.Count();
+  PRUint32 count = mLengths.Length();
 
-  if (count<=0) return NS_OK;
+  if (count == 0) return NS_OK;
 
-  PRInt32 i = 0;
+  PRUint32 i = 0;
   
   while (1) {
     nsISVGLength* length = ElementAt(i);
     nsCOMPtr<nsISVGValue> val = do_QueryInterface(length);
     NS_ASSERTION(val, "length doesn't implement required interface");
     if (!val) continue;
     nsAutoString str;
     val->GetValueString(str);
@@ -192,17 +192,17 @@ nsSVGLengthList::GetValueString(nsAStrin
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGLengthList methods:
 
 /* readonly attribute unsigned long numberOfItems; */
 NS_IMETHODIMP nsSVGLengthList::GetNumberOfItems(PRUint32 *aNumberOfItems)
 {
-  *aNumberOfItems = mLengths.Count();
+  *aNumberOfItems = mLengths.Length();
   return NS_OK;
 }
 
 /* void clear (); */
 NS_IMETHODIMP nsSVGLengthList::Clear()
 {
   WillModify();
   ReleaseLengths();
@@ -220,17 +220,17 @@ NS_IMETHODIMP nsSVGLengthList::Initializ
   }
   Clear();
   return AppendItem(newItem, _retval);
 }
 
 /* nsIDOMSVGLength getItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGLengthList::GetItem(PRUint32 index, nsIDOMSVGLength **_retval)
 {
-  if (index >= static_cast<PRUint32>(mLengths.Count())) {
+  if (index >= mLengths.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval  = ElementAt(index);
   NS_ADDREF(*_retval);
   return NS_OK;
 }
@@ -261,17 +261,17 @@ nsSVGLengthList::ReplaceItem(nsIDOMSVGLe
 
   NS_NOTYETIMPLEMENTED("nsSVGLengthList::ReplaceItem");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* nsIDOMSVGLengthList removeItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGLengthList::RemoveItem(PRUint32 index, nsIDOMSVGLength **_retval)
 {
-  if (index >= static_cast<PRUint32>(mLengths.Count())) {
+  if (index >= mLengths.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval = ElementAt(index);
   NS_ADDREF(*_retval);
   WillModify();
   RemoveElementAt(index);
@@ -316,46 +316,46 @@ nsSVGLengthList::DidModifySVGObservable(
 
 //----------------------------------------------------------------------
 // Implementation helpers
 
 void
 nsSVGLengthList::ReleaseLengths()
 {
   WillModify();
-  PRInt32 count = mLengths.Count();
-  for (PRInt32 i = 0; i < count; ++i) {
+  PRUint32 count = mLengths.Length();
+  for (PRUint32 i = 0; i < count; ++i) {
     nsISVGLength* length = ElementAt(i);
     length->SetContext(nsnull, 0);
     NS_REMOVE_SVGVALUE_OBSERVER(length);
     NS_RELEASE(length);
   }
   mLengths.Clear();
   DidModify();
 }
 
 nsISVGLength*
 nsSVGLengthList::ElementAt(PRInt32 index)
 {
-  return (nsISVGLength*)mLengths.ElementAt(index);
+  return mLengths.ElementAt(index);
 }
 
 void
 nsSVGLengthList::AppendElement(nsISVGLength* aElement)
 {
   WillModify();
   NS_ADDREF(aElement);
   
   // The SVG specs state that 'if newItem is already in a list, it
   // is removed from its previous list before it is inserted into this
   // list':
   //  aElement->SetListOwner(this);
   
   aElement->SetContext(mContext, mCtxType);
-  mLengths.AppendElement((void*)aElement);
+  mLengths.AppendElement(aElement);
   NS_ADD_SVGVALUE_OBSERVER(aElement);
   DidModify();
 }
 
 void
 nsSVGLengthList::RemoveElementAt(PRInt32 index)
 {
   WillModify();
@@ -375,17 +375,17 @@ nsSVGLengthList::InsertElementAt(nsISVGL
 
   // The SVG specs state that 'if newItem is already in a list, it
   // is removed from its previous list before it is inserted into this
   // list':
   //  aElement->SetListOwner(this);
   
   aElement->SetContext(mContext, mCtxType);
   
-  mLengths.InsertElementAt((void*)aElement, index);
+  mLengths.InsertElementAt(index, aElement);
   NS_ADD_SVGVALUE_OBSERVER(aElement);
   DidModify();
 }
 
 
 ////////////////////////////////////////////////////////////////////////
 // Exported creation functions:
 
--- a/content/svg/content/src/nsSVGNumberList.cpp
+++ b/content/svg/content/src/nsSVGNumberList.cpp
@@ -35,17 +35,16 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsSVGNumberList.h"
 #include "nsSVGNumber.h"
 #include "nsSVGValue.h"
 #include "nsWeakReference.h"
-#include "nsVoidArray.h"
 #include "nsDOMError.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "nsISVGValueUtils.h"
 #include "prdtoa.h"
 #include "nsContentUtils.h"
 
 ////////////////////////////////////////////////////////////////////////
@@ -86,17 +85,17 @@ protected:
   // implementation helpers:
   nsIDOMSVGNumber* ElementAt(PRInt32 index);
   void AppendElement(nsIDOMSVGNumber* aElement);
   void RemoveElementAt(PRInt32 index);
   nsresult InsertElementAt(nsIDOMSVGNumber* aElement, PRInt32 index);
   
   void ReleaseNumbers();
   
-  nsAutoVoidArray mNumbers;
+  nsAutoTArray<nsIDOMSVGNumber*, 8> mNumbers;
 };
 
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsSVGNumberList::nsSVGNumberList()
 {
@@ -160,21 +159,21 @@ nsSVGNumberList::SetValueString(const ns
   return rv;
 }
 
 NS_IMETHODIMP
 nsSVGNumberList::GetValueString(nsAString& aValue)
 {
   aValue.Truncate();
 
-  PRInt32 count = mNumbers.Count();
+  PRUint32 count = mNumbers.Length();
 
-  if (count<=0) return NS_OK;
+  if (count == 0) return NS_OK;
 
-  PRInt32 i = 0;
+  PRUint32 i = 0;
   
   while (1) {
     nsIDOMSVGNumber* number = ElementAt(i);
     nsCOMPtr<nsISVGValue> val = do_QueryInterface(number);
     NS_ASSERTION(val, "number doesn't implement required interface");
     if (!val) continue;
     nsAutoString str;
     val->GetValueString(str);
@@ -189,17 +188,17 @@ nsSVGNumberList::GetValueString(nsAStrin
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGNumberList methods:
 
 /* readonly attribute unsigned long numberOfItems; */
 NS_IMETHODIMP nsSVGNumberList::GetNumberOfItems(PRUint32 *aNumberOfItems)
 {
-  *aNumberOfItems = mNumbers.Count();
+  *aNumberOfItems = mNumbers.Length();
   return NS_OK;
 }
 
 /* void clear (); */
 NS_IMETHODIMP nsSVGNumberList::Clear()
 {
   WillModify();
   ReleaseNumbers();
@@ -217,17 +216,17 @@ NS_IMETHODIMP nsSVGNumberList::Initializ
   }
   Clear();
   return AppendItem(newItem, _retval);
 }
 
 /* nsIDOMSVGNumber getItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGNumberList::GetItem(PRUint32 index, nsIDOMSVGNumber **_retval)
 {
-  if (index >= static_cast<PRUint32>(mNumbers.Count())) {
+  if (index >= mNumbers.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval  = ElementAt(index);
   NS_ADDREF(*_retval);
   return NS_OK;
 }
@@ -239,20 +238,19 @@ nsSVGNumberList::InsertItemBefore(nsIDOM
                                   nsIDOMSVGNumber **_retval)
 {
   *_retval = newItem;
   if (!newItem)
     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
 
   nsSVGValueAutoNotifier autonotifier(this);
 
-  PRInt32 idx = index;
-  PRInt32 count = mNumbers.Count();
+  PRUint32 count = mNumbers.Length();
 
-  if (!InsertElementAt(newItem, (idx < count)? idx: count)) {
+  if (!InsertElementAt(newItem, (index < count)? index: count)) {
     *_retval = nsnull;
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
@@ -272,17 +270,17 @@ nsSVGNumberList::ReplaceItem(nsIDOMSVGNu
     return rv;
 
   return InsertElementAt(newItem, index);
 }
 
 /* nsIDOMSVGNumberList removeItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGNumberList::RemoveItem(PRUint32 index, nsIDOMSVGNumber **_retval)
 {
-  if (index >= static_cast<PRUint32>(mNumbers.Count())) {
+  if (index >= mNumbers.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval = ElementAt(index);
   NS_ADDREF(*_retval);
   WillModify();
   RemoveElementAt(index);
@@ -323,44 +321,44 @@ nsSVGNumberList::DidModifySVGObservable(
 
 //----------------------------------------------------------------------
 // Implementation helpers
 
 void
 nsSVGNumberList::ReleaseNumbers()
 {
   WillModify();
-  PRInt32 count = mNumbers.Count();
-  for (PRInt32 i = 0; i < count; ++i) {
+  PRUint32 count = mNumbers.Length();
+  for (PRUint32 i = 0; i < count; ++i) {
     nsIDOMSVGNumber* number = ElementAt(i);
     NS_REMOVE_SVGVALUE_OBSERVER(number);
     NS_RELEASE(number);
   }
   mNumbers.Clear();
   DidModify();
 }
 
 nsIDOMSVGNumber*
 nsSVGNumberList::ElementAt(PRInt32 index)
 {
-  return (nsIDOMSVGNumber*)mNumbers.ElementAt(index);
+  return mNumbers.ElementAt(index);
 }
 
 void
 nsSVGNumberList::AppendElement(nsIDOMSVGNumber* aElement)
 {
   WillModify();
   NS_ADDREF(aElement);
   
   // The SVG specs state that 'if newItem is already in a list, it
   // is removed from its previous list before it is inserted into this
   // list':
   //  aElement->SetListOwner(this);
   
-  mNumbers.AppendElement((void*)aElement);
+  mNumbers.AppendElement(aElement);
   NS_ADD_SVGVALUE_OBSERVER(aElement);
   DidModify();
 }
 
 void
 nsSVGNumberList::RemoveElementAt(PRInt32 index)
 {
   WillModify();
@@ -379,17 +377,17 @@ nsSVGNumberList::InsertElementAt(nsIDOMS
   WillModify();
   NS_ADDREF(aElement);
 
   // The SVG specs state that 'if newItem is already in a list, it
   // is removed from its previous list before it is inserted into this
   // list':
   //  aElement->SetListOwner(this);
   
-  if (!NS_FAILED(rv = mNumbers.InsertElementAt((void*)aElement, index)))
+  if (mNumbers.InsertElementAt(index, aElement))
     NS_ADD_SVGVALUE_OBSERVER(aElement);
   DidModify();
   return rv;
 }
 
 
 ////////////////////////////////////////////////////////////////////////
 // Exported creation functions:
--- a/content/svg/content/src/nsSVGPathDataParser.h
+++ b/content/svg/content/src/nsSVGPathDataParser.h
@@ -36,17 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_SVGPATHDATAPARSER_H__
 #define __NS_SVGPATHDATAPARSER_H__
 
 #include "nsSVGDataParser.h"
 #include "nsCOMPtr.h"
-#include "nsVoidArray.h"
 #include "nsCOMArray.h"
 #include "nsIDOMSVGPathSeg.h"
 #include "nsTArray.h"
 
 class nsSVGPathList;
 
 ////////////////////////////////////////////////////////////////////////
 // nsSVGPathDataParser: a simple recursive descent parser that builds
--- a/content/svg/content/src/nsSVGPathSegList.cpp
+++ b/content/svg/content/src/nsSVGPathSegList.cpp
@@ -35,17 +35,16 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsSVGPathSegList.h"
 #include "nsSVGPathSeg.h"
 #include "nsSVGValue.h"
 #include "nsWeakReference.h"
-#include "nsVoidArray.h"
 #include "nsCOMArray.h"
 #include "nsDOMError.h"
 #include "nsSVGPathDataParser.h"
 #include "nsReadableUtils.h"
 #include "nsContentUtils.h"
 
 ////////////////////////////////////////////////////////////////////////
 // nsSVGPathSegList
--- a/content/svg/content/src/nsSVGPointList.cpp
+++ b/content/svg/content/src/nsSVGPointList.cpp
@@ -77,40 +77,40 @@ nsSVGPointList::~nsSVGPointList()
 {
   ReleasePoints();
 }
 
 void
 nsSVGPointList::ReleasePoints()
 {
   WillModify();
-  PRInt32 count = mPoints.Count();
-  for (PRInt32 i = 0; i < count; ++i) {
+  PRUint32 count = mPoints.Length();
+  for (PRUint32 i = 0; i < count; ++i) {
     nsIDOMSVGPoint* point = ElementAt(i);
     nsCOMPtr<nsISVGValue> val = do_QueryInterface(point);
     if (val)
       val->RemoveObserver(this);
     NS_RELEASE(point);
   }
   mPoints.Clear();
   DidModify();
 }
 
 nsIDOMSVGPoint*
 nsSVGPointList::ElementAt(PRInt32 index)
 {
-  return (nsIDOMSVGPoint*)mPoints.ElementAt(index);
+  return mPoints.ElementAt(index);
 }
 
 void
 nsSVGPointList::AppendElement(nsIDOMSVGPoint* aElement)
 {
   WillModify();
   NS_ADDREF(aElement);
-  mPoints.AppendElement((void*)aElement);
+  mPoints.AppendElement(aElement);
   nsCOMPtr<nsISVGValue> val = do_QueryInterface(aElement);
   if (val)
     val->AddObserver(this);
   DidModify();
 }
 
 void
 nsSVGPointList::RemoveElementAt(PRInt32 index)
@@ -126,17 +126,17 @@ nsSVGPointList::RemoveElementAt(PRInt32 
   DidModify();
 }
 
 void
 nsSVGPointList::InsertElementAt(nsIDOMSVGPoint* aElement, PRInt32 index)
 {
   WillModify();
   NS_ADDREF(aElement);
-  mPoints.InsertElementAt((void*)aElement, index);
+  mPoints.InsertElementAt(index, aElement);
   nsCOMPtr<nsISVGValue> val = do_QueryInterface(aElement);
   if (val)
     val->AddObserver(this);
   DidModify();
 }
 
 //----------------------------------------------------------------------
 // nsISupports methods:
@@ -214,21 +214,21 @@ nsSVGPointList::SetValueString(const nsA
   return rv;
 }
 
 NS_IMETHODIMP
 nsSVGPointList::GetValueString(nsAString& aValue)
 {
   aValue.Truncate();
 
-  PRInt32 count = mPoints.Count();
+  PRUint32 count = mPoints.Length();
 
-  if (count<=0) return NS_OK;
+  if (count == 0) return NS_OK;
 
-  PRInt32 i = 0;
+  PRUint32 i = 0;
   PRUnichar buf[48];
   
   while (1) {
     nsIDOMSVGPoint* point = ElementAt(i);
     float x, y;
     point->GetX(&x);
     point->GetY(&y);
     
@@ -244,17 +244,17 @@ nsSVGPointList::GetValueString(nsAString
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGPointList methods:
 
 /* readonly attribute unsigned long numberOfItems; */
 NS_IMETHODIMP nsSVGPointList::GetNumberOfItems(PRUint32 *aNumberOfItems)
 {
-  *aNumberOfItems = mPoints.Count();
+  *aNumberOfItems = mPoints.Length();
   return NS_OK;
 }
 
 /* void clear (); */
 NS_IMETHODIMP nsSVGPointList::Clear()
 {
   WillModify();
   ReleasePoints();
@@ -272,17 +272,17 @@ NS_IMETHODIMP nsSVGPointList::Initialize
   }
   Clear();
   return AppendItem(newItem, _retval);
 }
 
 /* nsIDOMSVGPoint getItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGPointList::GetItem(PRUint32 index, nsIDOMSVGPoint **_retval)
 {
-  if (index >= static_cast<PRUint32>(mPoints.Count())) {
+  if (index >= mPoints.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval  = ElementAt(index);
   NS_ADDREF(*_retval);
   return NS_OK;
 }
@@ -311,17 +311,17 @@ NS_IMETHODIMP nsSVGPointList::ReplaceIte
 
   NS_NOTYETIMPLEMENTED("write me");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* nsIDOMSVGPoint removeItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGPointList::RemoveItem(PRUint32 index, nsIDOMSVGPoint **_retval)
 {
-  if (index >= static_cast<PRUint32>(mPoints.Count())) {
+  if (index >= mPoints.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval = ElementAt(index);
   NS_ADDREF(*_retval);
   WillModify();
   RemoveElementAt(index);
--- a/content/svg/content/src/nsSVGPointList.h
+++ b/content/svg/content/src/nsSVGPointList.h
@@ -38,17 +38,17 @@
 
 #ifndef __NS_SVGPOINTLIST_H__
 #define __NS_SVGPOINTLIST_H__
 
 #include "nsSVGValue.h"
 #include "nsISVGValueObserver.h"
 #include "nsWeakReference.h"
 #include "nsIDOMSVGPointList.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
 
 class nsSVGPointList : public nsSVGValue,
                        public nsIDOMSVGPointList,
                        public nsISVGValueObserver
 {
 public:
   static nsresult Create(const nsAString& aValue, nsISVGValue** aResult);
@@ -83,13 +83,13 @@ public:
   nsIDOMSVGPoint* ElementAt(PRInt32 index);
   void AppendElement(nsIDOMSVGPoint* aElement);
   void RemoveElementAt(PRInt32 index);
   void InsertElementAt(nsIDOMSVGPoint* aElement, PRInt32 index);
   
 protected:
   void ReleasePoints();
   
-  nsAutoVoidArray mPoints;
+  nsAutoTArray<nsIDOMSVGPoint*, 8> mPoints;
 };
 
 
 #endif //__NS_SVGPOINTLIST_H__
--- a/content/svg/content/src/nsSVGTransformList.cpp
+++ b/content/svg/content/src/nsSVGTransformList.cpp
@@ -75,43 +75,43 @@ nsSVGTransformList::nsSVGTransformList()
 nsSVGTransformList::~nsSVGTransformList()
 {
   ReleaseTransforms();
 }
 
 void
 nsSVGTransformList::ReleaseTransforms()
 {
-  PRInt32 count = mTransforms.Count();
-  for (PRInt32 i = 0; i < count; ++i) {
+  PRUint32 count = mTransforms.Length();
+  for (PRUint32 i = 0; i < count; ++i) {
     nsIDOMSVGTransform* transform = ElementAt(i);
     nsCOMPtr<nsISVGValue> val = do_QueryInterface(transform);
     val->RemoveObserver(this);
     NS_RELEASE(transform);
   }
   mTransforms.Clear();
 }
 
 nsIDOMSVGTransform*
 nsSVGTransformList::ElementAt(PRInt32 index)
 {
-  return (nsIDOMSVGTransform*)mTransforms.ElementAt(index);
+  return mTransforms.ElementAt(index);
 }
 
 PRBool
 nsSVGTransformList::AppendElement(nsIDOMSVGTransform* aElement)
 {
-  PRBool rv = mTransforms.AppendElement((void*)aElement);
-  if (rv) {
+  if (mTransforms.AppendElement(aElement)) {
     NS_ADDREF(aElement);
     nsCOMPtr<nsISVGValue> val = do_QueryInterface(aElement);
     val->AddObserver(this);
+    return PR_TRUE;
   }
 
-  return rv;
+  return PR_FALSE;
 }
 
 already_AddRefed<nsIDOMSVGMatrix>
 nsSVGTransformList::GetConsolidationMatrix(nsIDOMSVGTransformList *transforms)
 {
   PRUint32 count;
   transforms->GetNumberOfItems(&count);
 
@@ -194,21 +194,21 @@ nsSVGTransformList::SetValueString(const
   return rv;
 }
 
 NS_IMETHODIMP
 nsSVGTransformList::GetValueString(nsAString& aValue)
 {
   aValue.Truncate();
 
-  PRInt32 count = mTransforms.Count();
+  PRUint32 count = mTransforms.Length();
 
-  if (count<=0) return NS_OK;
+  if (count == 0) return NS_OK;
 
-  PRInt32 i = 0;
+  PRUint32 i = 0;
   
   while (1) {
     nsIDOMSVGTransform* transform = ElementAt(i);
 
     nsCOMPtr<nsISVGValue> val = do_QueryInterface(transform);
     nsAutoString str;
     val->GetValueString(str);
     aValue.Append(str);
@@ -223,17 +223,17 @@ nsSVGTransformList::GetValueString(nsASt
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGTransformList methods:
 
 /* readonly attribute unsigned long numberOfItems; */
 NS_IMETHODIMP nsSVGTransformList::GetNumberOfItems(PRUint32 *aNumberOfItems)
 {
-  *aNumberOfItems = mTransforms.Count();
+  *aNumberOfItems = mTransforms.Length();
   return NS_OK;
 }
 
 /* void clear (); */
 NS_IMETHODIMP nsSVGTransformList::Clear()
 {
   WillModify();
   ReleaseTransforms();
@@ -257,17 +257,17 @@ NS_IMETHODIMP nsSVGTransformList::Initia
   *_retval = newItem;
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 /* nsIDOMSVGTransform getItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGTransformList::GetItem(PRUint32 index, nsIDOMSVGTransform **_retval)
 {
-  if (index >= static_cast<PRUint32>(mTransforms.Count())) {
+  if (index >= mTransforms.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval  = ElementAt(index);
   NS_ADDREF(*_retval);
   return NS_OK;
 }
@@ -276,19 +276,19 @@ NS_IMETHODIMP nsSVGTransformList::GetIte
 NS_IMETHODIMP nsSVGTransformList::InsertItemBefore(nsIDOMSVGTransform *newItem,
                                                    PRUint32 index,
                                                    nsIDOMSVGTransform **_retval)
 {
   NS_ENSURE_NATIVE_TRANSFORM(newItem, _retval);
 
   nsSVGValueAutoNotifier autonotifier(this);
 
-  PRUint32 count = mTransforms.Count();
+  PRUint32 count = mTransforms.Length();
 
-  if (!mTransforms.InsertElementAt((void*)newItem, (index < count)? index: count)) {
+  if (!mTransforms.InsertElementAt((index < count)? index: count, newItem)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(newItem);
   nsCOMPtr<nsISVGValue> val = do_QueryInterface(newItem);
   val->AddObserver(this);
 
   *_retval = newItem;
@@ -300,25 +300,22 @@ NS_IMETHODIMP nsSVGTransformList::Insert
 NS_IMETHODIMP nsSVGTransformList::ReplaceItem(nsIDOMSVGTransform *newItem,
                                               PRUint32 index,
                                               nsIDOMSVGTransform **_retval)
 {
   NS_ENSURE_NATIVE_TRANSFORM(newItem, _retval);
 
   nsSVGValueAutoNotifier autonotifier(this);
 
-  if (index >= PRUint32(mTransforms.Count()))
+  if (index >= mTransforms.Length())
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
 
   nsIDOMSVGTransform* oldItem = ElementAt(index);
 
-  if (!mTransforms.ReplaceElementAt((void*)newItem, index)) {
-    NS_NOTREACHED("removal of element failed");
-    return NS_ERROR_UNEXPECTED;
-  }
+  mTransforms.ElementAt(index) = newItem;
 
   nsCOMPtr<nsISVGValue> val = do_QueryInterface(oldItem);
   val->RemoveObserver(this);
   NS_RELEASE(oldItem);
   val = do_QueryInterface(newItem);
   val->AddObserver(this);
   NS_ADDREF(newItem);
 
@@ -327,28 +324,24 @@ NS_IMETHODIMP nsSVGTransformList::Replac
   return NS_OK;
 }
 
 /* nsIDOMSVGTransform removeItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGTransformList::RemoveItem(PRUint32 index, nsIDOMSVGTransform **_retval)
 {
   nsSVGValueAutoNotifier autonotifier(this);
 
-  if (index >= static_cast<PRUint32>(mTransforms.Count())) {
+  if (index >= mTransforms.Length()) {
     *_retval = nsnull;
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   *_retval = ElementAt(index);
 
-  if (!mTransforms.RemoveElementAt(index)) {
-    NS_NOTREACHED("removal of element failed");
-    *_retval = nsnull;
-    return NS_ERROR_UNEXPECTED;
-  }
+  mTransforms.RemoveElementAt(index);
 
   nsCOMPtr<nsISVGValue> val = do_QueryInterface(*_retval);
   val->RemoveObserver(this);
 
   // don't NS_ADDREF(*_retval)
   return NS_OK;
 }
 
@@ -387,17 +380,17 @@ nsSVGTransformList::CreateSVGTransformFr
 
 /* nsIDOMSVGTransform consolidate (); */
 NS_IMETHODIMP nsSVGTransformList::Consolidate(nsIDOMSVGTransform **_retval)
 {
   // Note we don't want WillModify/DidModify since nothing really changes
 
   *_retval = nsnull;
 
-  PRInt32 count = mTransforms.Count();
+  PRUint32 count = mTransforms.Length();
   if (count==0) return NS_OK;
   if (count==1) {
     *_retval = ElementAt(0);
     NS_ADDREF(*_retval);
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMSVGMatrix> conmatrix = GetConsolidationMatrix(this);
--- a/content/svg/content/src/nsSVGTransformList.h
+++ b/content/svg/content/src/nsSVGTransformList.h
@@ -38,17 +38,17 @@
 
 #ifndef __NS_SVGTRANSFORMLIST_H__
 #define __NS_SVGTRANSFORMLIST_H__
 
 #include "nsSVGValue.h"
 #include "nsISVGValueObserver.h"
 #include "nsWeakReference.h"
 #include "nsIDOMSVGTransformList.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
 class nsSVGTransformList : public nsSVGValue,
                            public nsIDOMSVGTransformList,
                            public nsISVGValueObserver
 {
 public:
   static nsresult Create(nsIDOMSVGTransformList** aResult);
   
@@ -82,13 +82,13 @@ public:
   PRBool AppendElement(nsIDOMSVGTransform* aElement);
   static already_AddRefed<nsIDOMSVGMatrix>
   GetConsolidationMatrix(nsIDOMSVGTransformList *transforms);
   
 protected:
   PRInt32 ParseParameterList(char *paramstr, float *vars, PRInt32 nvars);
   void ReleaseTransforms();
   
-  nsAutoVoidArray mTransforms;
+  nsAutoTArray<nsIDOMSVGTransform*, 8> mTransforms;
 };
 
 
 #endif //__NS_SVGTRANSFORMLIST_H__
--- a/content/svg/content/src/nsSVGValue.cpp
+++ b/content/svg/content/src/nsSVGValue.cpp
@@ -47,37 +47,36 @@ nsSVGValue::nsSVGValue()
 nsSVGValue::~nsSVGValue()
 {
   ReleaseObservers();
 }
 
 void
 nsSVGValue::ReleaseObservers()
 {
-  PRInt32 count = mObservers.Count();
-  PRInt32 i;
+  PRUint32 count = mObservers.Length();
+  PRUint32 i;
   for (i = 0; i < count; ++i) {
-    nsIWeakReference* wr = static_cast<nsIWeakReference*>(mObservers.ElementAt(i));
+    nsIWeakReference* wr = mObservers.ElementAt(i);
     NS_RELEASE(wr);
   }
-  while (i)
-    mObservers.RemoveElementAt(--i);
+  mObservers.Clear();
 }
 
 void
 nsSVGValue::NotifyObservers(SVGObserverNotifyFunction f,
                             modificationType aModType)
 {
-  PRInt32 count = mObservers.Count();
+  PRInt32 count = mObservers.Length();
 
   // Since notification might cause the listeners to remove themselves
   // from the observer list (mod_die), walk backwards through the list
   // to catch everyone.
   for (PRInt32 i = count - 1; i >= 0; i--) {
-    nsIWeakReference* wr = static_cast<nsIWeakReference*>(mObservers.ElementAt(i));
+    nsIWeakReference* wr = mObservers.ElementAt(i);
     nsCOMPtr<nsISVGValueObserver> observer = do_QueryReferent(wr);
     if (observer)
        (static_cast<nsISVGValueObserver*>(observer)->*f)(this, aModType);
   }
 }
 
 void
 nsSVGValue::WillModify(modificationType aModType)
@@ -103,33 +102,33 @@ nsSVGValue::AddObserver(nsISVGValueObser
   nsIWeakReference* wr = NS_GetWeakReference(observer);
   if (!wr) return NS_ERROR_FAILURE;
 
   // Prevent duplicate observers - needed because geometry can attempt
   // to add itself as an observer of a paint server for both the
   // stroke and fill.  Safe, as on a style change we remove both, as
   // the change notification isn't fine grained, and re-add as
   // appropriate.
-  if (mObservers.IndexOf((void*)wr) >= 0) {
+  if (mObservers.Contains(wr)) {
     NS_RELEASE(wr);
     return NS_OK;
   }
 
-  mObservers.AppendElement((void*)wr);
+  mObservers.AppendElement(wr);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSVGValue::RemoveObserver(nsISVGValueObserver* observer)
 {
   nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(observer);
   if (!wr) return NS_ERROR_FAILURE;
-  PRInt32 i = mObservers.IndexOf((void*)wr);
+  PRInt32 i = mObservers.IndexOf(wr);
   if (i<0) return NS_ERROR_FAILURE;
-  nsIWeakReference* wr2 = static_cast<nsIWeakReference*>(mObservers.ElementAt(i));
+  nsIWeakReference* wr2 = mObservers.ElementAt(i);
   NS_RELEASE(wr2);
   mObservers.RemoveElementAt(i);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSVGValue::BeginBatchUpdate()
 {
--- a/content/svg/content/src/nsSVGValue.h
+++ b/content/svg/content/src/nsSVGValue.h
@@ -37,17 +37,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_SVGVALUE_H__
 #define __NS_SVGVALUE_H__
 
 #include "nscore.h"
 #include "nsISVGValue.h"
 #include "nsAutoPtr.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsISVGValueObserver.h"
 
 class nsSVGValue : public nsISVGValue
 {
 protected:
   nsSVGValue();
   virtual ~nsSVGValue();
 
@@ -75,17 +75,17 @@ protected:
   // implementation helpers
   void ReleaseObservers();
   void NotifyObservers(SVGObserverNotifyFunction f,
                        modificationType aModType);
   PRInt32 GetModifyNestCount() { return mModifyNestCount; }
 private:
   virtual void OnDidModify(){} // hook that will be called before observers are notified
   
-  nsSmallVoidArray mObservers;
+  nsAutoTArray<nsIWeakReference*, 1> mObservers;
   PRInt32 mModifyNestCount;
 };
 
 // Class that will automatically call WillModify and DidModify in its ctor
 // and dtor respectively (for functions that have multiple exit points).
 
 class NS_STACK_CLASS nsSVGValueAutoNotifier
 {
--- a/content/xbl/src/nsXBLEventHandler.cpp
+++ b/content/xbl/src/nsXBLEventHandler.cpp
@@ -131,35 +131,34 @@ nsXBLKeyEventHandler::ExecuteMatchedHand
   if (domNSEvent)
     domNSEvent->GetIsTrusted(&trustedEvent);
 
   nsCOMPtr<nsIDOMEventTarget> target;
   aKeyEvent->GetCurrentTarget(getter_AddRefs(target));
   nsCOMPtr<nsPIDOMEventTarget> piTarget = do_QueryInterface(target);
 
   PRBool executed = PR_FALSE;
-  for (PRUint32 i = 0; i < mProtoHandlers.Count(); ++i) {
-    nsXBLPrototypeHandler* handler = static_cast<nsXBLPrototypeHandler*>
-                                                (mProtoHandlers[i]);
+  for (PRUint32 i = 0; i < mProtoHandlers.Length(); ++i) {
+    nsXBLPrototypeHandler* handler = mProtoHandlers[i];
     PRBool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr();
     if ((trustedEvent ||
         (hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
         (!hasAllowUntrustedAttr && !mIsBoundToChrome)) &&
         handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreShiftKey)) {
       handler->ExecuteHandler(piTarget, aKeyEvent);
       executed = PR_TRUE;
     }
   }
   return executed;
 }
 
 NS_IMETHODIMP
 nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
 {
-  PRUint32 count = mProtoHandlers.Count();
+  PRUint32 count = mProtoHandlers.Length();
   if (count == 0)
     return NS_ERROR_FAILURE;
 
   if (mPhase == NS_PHASE_TARGET) {
     PRUint16 eventPhase;
     aEvent->GetEventPhase(&eventPhase);
     if (eventPhase != nsIDOMEvent::AT_TARGET)
       return NS_OK;
--- a/content/xbl/src/nsXBLEventHandler.h
+++ b/content/xbl/src/nsXBLEventHandler.h
@@ -36,17 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsXBLEventHandler_h__
 #define nsXBLEventHandler_h__
 
 #include "nsCOMPtr.h"
 #include "nsIDOMEventListener.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
 class nsIAtom;
 class nsIContent;
 class nsIDOM3EventTarget;
 class nsIDOMKeyEvent;
 class nsPIDOMEventTarget;
 class nsXBLPrototypeHandler;
 
@@ -120,17 +120,17 @@ public:
   {
     mIsBoundToChrome = aIsBoundToChrome;
   }
 private:
   nsXBLKeyEventHandler();
   PRBool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, PRUint32 aCharCode,
                                 PRBool aIgnoreShiftKey);
 
-  nsVoidArray mProtoHandlers;
+  nsTArray<nsXBLPrototypeHandler*> mProtoHandlers;
   nsCOMPtr<nsIAtom> mEventType;
   PRUint8 mPhase;
   PRUint8 mType;
   PRPackedBool mIsBoundToChrome;
 };
 
 nsresult
 NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
--- a/content/xbl/src/nsXBLService.cpp
+++ b/content/xbl/src/nsXBLService.cpp
@@ -69,16 +69,17 @@
 #include "nsXBLBinding.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsIXBLDocumentInfo.h"
 #include "nsCRT.h"
 #include "nsContentUtils.h"
 #include "nsSyncLoadService.h"
 #include "nsIDOM3Node.h"
 #include "nsContentPolicyUtils.h"
+#include "nsTArray.h"
 
 #include "nsIPresShell.h"
 #include "nsIDocumentObserver.h"
 #include "nsFrameManager.h"
 #include "nsStyleContext.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIScriptError.h"
 
@@ -327,17 +328,17 @@ public:
 
   void AddRequest(nsXBLBindingRequest* aRequest) { mBindingRequests.AppendElement(aRequest); }
   PRBool HasRequest(nsIURI* aURI, nsIContent* aBoundElement);
 
 private:
   nsXBLService* mXBLService; // [WEAK]
 
   nsCOMPtr<nsIStreamListener> mInner;
-  nsAutoVoidArray mBindingRequests;
+  nsAutoTArray<nsXBLBindingRequest*, 8> mBindingRequests;
   
   nsCOMPtr<nsIWeakReference> mBoundDocument;
   nsCOMPtr<nsIXMLContentSink> mSink; // Only set until OnStartRequest
   nsCOMPtr<nsIDocument> mBindingDocument; // Only set until OnStartRequest
 };
 
 /* Implementation file */
 NS_IMPL_ISUPPORTS4(nsXBLStreamListener, nsIStreamListener, nsIRequestObserver, nsIDOMLoadListener, nsIDOMEventListener)
@@ -350,18 +351,18 @@ nsXBLStreamListener::nsXBLStreamListener
 {
   /* member initializers and constructor code */
   mXBLService = aXBLService;
   mBoundDocument = do_GetWeakReference(aBoundDocument);
 }
 
 nsXBLStreamListener::~nsXBLStreamListener()
 {
-  for (PRInt32 i = 0; i < mBindingRequests.Count(); i++) {
-    nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
+  for (PRInt32 i = 0; i < mBindingRequests.Length(); i++) {
+    nsXBLBindingRequest* req = mBindingRequests.ElementAt(i);
     nsXBLBindingRequest::Destroy(mXBLService->mPool, req);
   }
 }
 
 NS_IMETHODIMP
 nsXBLStreamListener::OnDataAvailable(nsIRequest *request, nsISupports* aCtxt, nsIInputStream* aInStr, 
                                      PRUint32 aSourceOffset, PRUint32 aCount)
 {
@@ -416,34 +417,34 @@ nsXBLStreamListener::OnStopRequest(nsIRe
 
   return rv;
 }
 
 PRBool
 nsXBLStreamListener::HasRequest(nsIURI* aURI, nsIContent* aElt)
 {
   // XXX Could be more efficient.
-  PRUint32 count = mBindingRequests.Count();
+  PRUint32 count = mBindingRequests.Length();
   for (PRUint32 i = 0; i < count; i++) {
-    nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
+    nsXBLBindingRequest* req = mBindingRequests.ElementAt(i);
     PRBool eq;
     if (req->mBoundElement == aElt &&
         NS_SUCCEEDED(req->mBindingURI->Equals(aURI, &eq)) && eq)
       return PR_TRUE;
   }
 
   return PR_FALSE;
 }
 
 nsresult
 nsXBLStreamListener::Load(nsIDOMEvent* aEvent)
 {
   nsresult rv = NS_OK;
   PRUint32 i;
-  PRUint32 count = mBindingRequests.Count();
+  PRUint32 count = mBindingRequests.Length();
 
   // Get the binding document; note that we don't hold onto it in this object
   // to avoid creating a cycle
   nsCOMPtr<nsIDOMEventTarget> target;
   aEvent->GetCurrentTarget(getter_AddRefs(target));
   nsCOMPtr<nsIDocument> bindingDocument = do_QueryInterface(target);
   NS_ASSERTION(bindingDocument, "Event not targeted at document?!");
 
@@ -455,17 +456,17 @@ nsXBLStreamListener::Load(nsIDOMEvent* a
   else {
     // We have to do a flush prior to notification of the document load.
     // This has to happen since the HTML content sink can be holding on
     // to notifications related to our children (e.g., if you bind to the
     // <body> tag) that result in duplication of content.  
     // We need to get the sink's notifications flushed and then make the binding
     // ready.
     if (count > 0) {
-      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(0);
+      nsXBLBindingRequest* req = mBindingRequests.ElementAt(0);
       nsIDocument* document = req->mBoundElement->GetCurrentDoc();
       if (document)
         document->FlushPendingNotifications(Flush_ContentAndNotify);
     }
 
     // Remove ourselves from the set of pending docs.
     nsBindingManager *bindingManager = doc->BindingManager();
     nsIURI* documentURI = bindingDocument->GetDocumentURI();
@@ -495,17 +496,17 @@ nsXBLStreamListener::Load(nsIDOMEvent* a
     }
 #endif
   
     bindingManager->PutXBLDocumentInfo(info);
 
     // Notify all pending requests that their bindings are
     // ready and can be installed.
     for (i = 0; i < count; i++) {
-      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
+      nsXBLBindingRequest* req = mBindingRequests.ElementAt(i);
       req->DocumentLoaded(bindingDocument);
     }
   }
 
   target->RemoveEventListener(NS_LITERAL_STRING("load"), (nsIDOMLoadListener*)this, PR_FALSE);
 
   return rv;
 }
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -53,17 +53,16 @@
 #include "nsIDocShellTreeItem.h"
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIDOMComment.h"
 #include "nsIDOMCDATASection.h"
 #include "nsDOMDocumentType.h"
 #include "nsHTMLParts.h"
-#include "nsVoidArray.h"
 #include "nsCRT.h"
 #include "nsICSSLoader.h"
 #include "nsICSSStyleSheet.h"
 #include "nsGkAtoms.h"
 #include "nsContentUtils.h"
 #include "nsIScriptContext.h"
 #include "nsINameSpaceManager.h"
 #include "nsIServiceManager.h"
--- a/content/xslt/src/base/txNamespaceMap.cpp
+++ b/content/xslt/src/base/txNamespaceMap.cpp
@@ -74,27 +74,27 @@ txNamespaceMap::mapNamespace(nsIAtom* aP
     else {
         nsId = txNamespaceManager::getNamespaceID(aNamespaceURI);
         NS_ENSURE_FALSE(nsId == kNameSpaceID_Unknown, NS_ERROR_FAILURE);
     }
 
     // Check if the mapping already exists
     PRInt32 index = mPrefixes.IndexOf(prefix);
     if (index >= 0) {
-        mNamespaces.ReplaceElementAt(NS_INT32_TO_PTR(nsId), index);
+        mNamespaces.ElementAt(index) = nsId;
 
         return NS_OK;
     }
 
     // New mapping
     if (!mPrefixes.AppendObject(prefix)) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
     
-    if (!mNamespaces.AppendElement(NS_INT32_TO_PTR(nsId))) {
+    if (mNamespaces.AppendElement(nsId) == nsnull) {
         mPrefixes.RemoveObjectAt(mPrefixes.Count() - 1);
 
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
     return NS_OK;
 }
 
@@ -104,17 +104,17 @@ txNamespaceMap::lookupNamespace(nsIAtom*
     if (aPrefix == txXMLAtoms::xml) {
         return kNameSpaceID_XML;
     }
 
     nsIAtom* prefix = aPrefix == txXMLAtoms::_empty ? 0 : aPrefix;
 
     PRInt32 index = mPrefixes.IndexOf(prefix);
     if (index >= 0) {
-        return NS_PTR_TO_INT32(mNamespaces.SafeElementAt(index));
+        return mNamespaces.SafeElementAt(index, kNameSpaceID_Unknown);
     }
 
     if (!prefix) {
         return kNameSpaceID_None;
     }
 
     return kNameSpaceID_Unknown;
 }
--- a/content/xslt/src/base/txNamespaceMap.h
+++ b/content/xslt/src/base/txNamespaceMap.h
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef TRANSFRMX_TXNAMESPACEMAP_H
 #define TRANSFRMX_TXNAMESPACEMAP_H
 
 #include "nsIAtom.h"
 #include "nsCOMArray.h"
+#include "nsTArray.h"
 
 class txNamespaceMap
 {
 public:
     txNamespaceMap();
     txNamespaceMap(const txNamespaceMap& aOther);
 
     nsrefcnt AddRef()
@@ -65,12 +66,12 @@ public:
     nsresult mapNamespace(nsIAtom* aPrefix, const nsAString& aNamespaceURI);
     PRInt32 lookupNamespace(nsIAtom* aPrefix);
     PRInt32 lookupNamespace(const nsAString& aPrefix);
     PRInt32 lookupNamespaceWithDefault(const nsAString& aPrefix);
 
 private:
     nsAutoRefCnt mRefCnt;
     nsCOMArray<nsIAtom> mPrefixes;
-    nsVoidArray mNamespaces;
+    nsTArray<PRInt32> mNamespaces;
 };
 
 #endif //TRANSFRMX_TXNAMESPACEMAP_H
--- a/content/xslt/src/base/txStack.h
+++ b/content/xslt/src/base/txStack.h
@@ -34,78 +34,81 @@
  * 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 txStack_h___
 #define txStack_h___
 
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
-class txStack : private nsVoidArray
+class txStack : private nsTArray<void*>
 {
 public:
     /**
      * Returns the specified object from the top of this stack,
      * without removing it from the stack.
      *
      * @return a pointer to the object that is the top of this stack.
      */
     inline void* peek()
     {
         NS_ASSERTION(!isEmpty(), "peeking at empty stack");
-        return ElementAt(Count() - 1);
+        return !isEmpty() ? ElementAt(Length() - 1) : nsnull;
     }
 
     /**
      * Adds the specified object to the top of this stack.
      *
      * @param obj a pointer to the object that is to be added to the
      * top of this stack.
      */
     inline nsresult push(void* aObject)
     {
-        return InsertElementAt(aObject, Count()) ? NS_OK :
-                                                   NS_ERROR_OUT_OF_MEMORY;
+        return AppendElement(aObject) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
     }
 
     /**
      * Removes and returns the specified object from the top of this
      * stack.
      *
      * @return a pointer to the object that was the top of this stack.
      */
     inline void* pop()
     {
+        void* object = nsnull;
         NS_ASSERTION(!isEmpty(), "popping from empty stack");
-        const PRInt32 count = Count() - 1;
-        void* object = ElementAt(count);
-        RemoveElementsAt(count, 1);
+        if (!isEmpty())
+        {
+            const PRUint32 count = Length() - 1;
+            object = ElementAt(count);
+            RemoveElementAt(count);
+        }
         return object;
     }
 
     /**
      * Returns true if there are no objects in the stack.
      *
      * @return true if there are no objects in the stack.
      */
     inline PRBool isEmpty()
     {
-        return (Count() <= 0);
+        return IsEmpty();
     }
 
     /**
      * Returns the number of elements in the Stack.
      *
      * @return the number of elements in the Stack.
      */
     inline PRInt32 size()
     {
-        return Count();
+        return Length();
     }
 
 private:
     friend class txStackIterator;
 };
 
 class txStackIterator
 {
@@ -123,30 +126,30 @@ public:
 
     /**
      * Returns true if there is more objects on the stack.
      *
      * @return .
      */
     inline PRBool hasNext()
     {
-        return (mPosition < mStack->Count());
+        return (mPosition < mStack->Length());
     }
 
     /**
      * Returns the next object pointer from the stack.
      *
      * @return .
      */
     inline void* next()
     {
-        if (mPosition == mStack->Count()) {
+        if (mPosition == mStack->Length()) {
             return nsnull;
         }
         return mStack->ElementAt(mPosition++);
     }
 
 private:
     txStack* mStack;
-    PRInt32 mPosition;
+    PRUint32 mPosition;
 };
 
 #endif /* txStack_h___ */
--- a/content/xslt/src/main/testXalan.cpp
+++ b/content/xslt/src/main/testXalan.cpp
@@ -39,17 +39,16 @@
 #include "txStandaloneXSLTProcessor.h"
 #include "nsXPCOM.h"
 #include <fstream.h>
 #include "nsDoubleHashtable.h"
 #include "nsIComponentManager.h"
 #include "nsILocalFile.h"
 #include "nsISimpleEnumerator.h"
 #include "nsString.h"
-#include "nsVoidArray.h"
 #include "prenv.h"
 #include "prsystem.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 
 #ifdef NS_TRACE_MALLOC
 #include "nsTraceMalloc.h"
 #endif
--- a/content/xslt/src/xml/txDOM.h
+++ b/content/xslt/src/xml/txDOM.h
@@ -52,17 +52,16 @@
 #ifdef __BORLANDC__
 #include <stdlib.h>
 #endif
 
 #include "txList.h"
 #include "nsIAtom.h"
 #include "nsDoubleHashtable.h"
 #include "nsString.h"
-#include "nsVoidArray.h"
 #include "txCore.h"
 #include "nsAutoPtr.h"
 
 #define kTxNsNodeIndexOffset 0x00000000;
 #define kTxAttrIndexOffset 0x40000000;
 #define kTxChildIndexOffset 0x80000000;
 
 class NamedNodeMap;
--- a/content/xslt/src/xml/txNodeDefinition.cpp
+++ b/content/xslt/src/xml/txNodeDefinition.cpp
@@ -41,17 +41,16 @@
 //    Implementation of the NodeDefinition Class
 //
 // Modification History:
 // Who  When      What
 // TK   03/29/99  Created
 //
 
 #include "txDOM.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "txURIUtils.h"
 #include "txAtoms.h"
 #include <string.h>
 
 NodeDefinition::NodeDefinition(NodeType type, nsIAtom *aLocalName,
                                const nsAString& value, Document* owner) :
     mLocalName(aLocalName),
--- a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
+++ b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
@@ -49,16 +49,17 @@
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsTextFragment.h"
 #include "txXMLUtils.h"
 #include "txLog.h"
 #include "nsUnicharUtils.h"
 #include "nsAttrName.h"
+#include "nsTArray.h"
 
 const PRUint32 kUnknownIndex = PRUint32(-1);
 
 txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther)
     : mPosition(aOther.mPosition),
       mCurrentIndex(aOther.mCurrentIndex)
 {
 }
@@ -204,19 +205,19 @@ txXPathTreeWalker::moveToNamedAttribute(
 PRBool
 txXPathTreeWalker::moveToFirstChild()
 {
     if (mPosition.isAttribute()) {
         return PR_FALSE;
     }
 
     NS_ASSERTION(!mPosition.isDocument() ||
-                 (mCurrentIndex == kUnknownIndex && !mDescendants.Count()),
+                 (mCurrentIndex == kUnknownIndex && mDescendants.IsEmpty()),
                  "we shouldn't have any position info at the document");
-    NS_ASSERTION(mCurrentIndex != kUnknownIndex || !mDescendants.Count(),
+    NS_ASSERTION(mCurrentIndex != kUnknownIndex || mDescendants.IsEmpty(),
                  "Index should be known if parents index are");
 
     nsIContent* child = mPosition.mNode->GetChildAt(0);
     if (!child) {
         return PR_FALSE;
     }
     mPosition.mIndex = txXPathNode::eContent;
     mPosition.mNode = child;
@@ -233,19 +234,19 @@ txXPathTreeWalker::moveToFirstChild()
 PRBool
 txXPathTreeWalker::moveToLastChild()
 {
     if (mPosition.isAttribute()) {
         return PR_FALSE;
     }
 
     NS_ASSERTION(!mPosition.isDocument() ||
-                 (mCurrentIndex == kUnknownIndex && !mDescendants.Count()),
+                 (mCurrentIndex == kUnknownIndex && mDescendants.IsEmpty()),
                  "we shouldn't have any position info at the document");
-    NS_ASSERTION(mCurrentIndex != kUnknownIndex || !mDescendants.Count(),
+    NS_ASSERTION(mCurrentIndex != kUnknownIndex || mDescendants.IsEmpty(),
                  "Index should be known if parents index are");
 
     PRUint32 total = mPosition.mNode->GetChildCount();
     if (!total) {
         return PR_FALSE;
     }
     mPosition.mNode = mPosition.mNode->GetChildAt(total - 1);
 
@@ -291,17 +292,17 @@ txXPathTreeWalker::moveToParent()
         return PR_TRUE;
     }
 
     nsINode* parent = mPosition.mNode->GetNodeParent();
     if (!parent) {
         return PR_FALSE;
     }
 
-    PRInt32 count = mDescendants.Count();
+    PRUint32 count = mDescendants.Length();
     if (count) {
         mCurrentIndex = mDescendants.ValueAt(--count);
         mDescendants.RemoveValueAt(count);
     }
     else {
         mCurrentIndex = kUnknownIndex;
     }
 
@@ -686,17 +687,17 @@ txXPathNodeUtils::comparePosition(const 
     if (document != otherDocument) {
         return document < otherDocument ? -1 : 1;
     }
 
     // Now either both nodes are in orphan trees, or they are both in the
     // same tree.
 
     // Get parents up the tree.
-    nsAutoVoidArray parents, otherParents;
+    nsAutoTArray<nsINode*, 8> parents, otherParents;
     nsINode* node = aNode.mNode;
     nsINode* otherNode = aOtherNode.mNode;
     nsINode* parent, *otherParent;
     while (node && otherNode) {
         parent = node->GetNodeParent();
         otherParent = otherNode->GetNodeParent();
 
         // Hopefully this is a common case.
@@ -722,27 +723,26 @@ txXPathNodeUtils::comparePosition(const 
         node = node->GetNodeParent();
     }
     while (otherNode) {
         otherParents.AppendElement(otherNode);
         otherNode = otherNode->GetNodeParent();
     }
 
     // Walk back down along the parent-chains until we find where they split.
-    PRInt32 total = parents.Count() - 1;
-    PRInt32 otherTotal = otherParents.Count() - 1;
+    PRInt32 total = parents.Length() - 1;
+    PRInt32 otherTotal = otherParents.Length() - 1;
     NS_ASSERTION(total != otherTotal, "Can't have same number of parents");
 
     PRInt32 lastIndex = PR_MIN(total, otherTotal);
     PRInt32 i;
     parent = nsnull;
     for (i = 0; i <= lastIndex; ++i) {
-        node = static_cast<nsINode*>(parents.ElementAt(total - i));
-        otherNode = static_cast<nsINode*>
-                               (otherParents.ElementAt(otherTotal - i));
+        node = parents.ElementAt(total - i);
+        otherNode = otherParents.ElementAt(otherTotal - i);
         if (node != otherNode) {
             if (!parent) {
                 // The two nodes are in different orphan subtrees.
                 NS_ASSERTION(i == 0, "this shouldn't happen");
                 return node < otherNode ? -1 : 1;
             }
 
             PRInt32 index = parent->IndexOf(node);
--- a/content/xslt/src/xpath/txNodeSet.h
+++ b/content/xslt/src/xpath/txNodeSet.h
@@ -39,17 +39,16 @@
 /**
  * Implementation of an XPath NodeSet
  */
 
 #ifndef txNodeSet_h__
 #define txNodeSet_h__
 
 #include "txExprResult.h"
-#include "nsVoidArray.h"
 #include "txError.h"
 #include "txXPathNode.h"
 
 class txNodeSet : public txAExprResult
 {
 public:
     /**
      * Creates a new empty NodeSet
--- a/content/xslt/src/xpath/txXPathTreeWalker.h
+++ b/content/xslt/src/xpath/txXPathTreeWalker.h
@@ -41,32 +41,35 @@
 
 #include "txCore.h"
 #include "txXPathNode.h"
 
 class nsIAtom;
 
 #ifndef TX_EXE
 #include "nsINodeInfo.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
-class txUint32Array : public nsVoidArray
+class txUint32Array : public nsTArray<PRUint32>
 {
 public:
     PRBool AppendValue(PRUint32 aValue)
     {
-        return InsertElementAt(NS_INT32_TO_PTR(aValue), Count());
+        return AppendElement(aValue) != nsnull;
     }
     PRBool RemoveValueAt(PRUint32 aIndex)
     {
-        return RemoveElementsAt(aIndex, 1);
+        if (aIndex < Length()) {
+            RemoveElementAt(aIndex);
+        }
+        return PR_TRUE;
     }
-    PRInt32 ValueAt(PRUint32 aIndex) const
+    PRUint32 ValueAt(PRUint32 aIndex) const
     {
-        return NS_PTR_TO_INT32(ElementAt(aIndex));
+        return (aIndex < Length()) ? ElementAt(aIndex) : 0;
     }
 };
 
 class nsIDOMDocument;
 #endif
 
 class txXPathTreeWalker
 {
--- a/content/xslt/src/xslt/txBufferingHandler.cpp
+++ b/content/xslt/src/xslt/txBufferingHandler.cpp
@@ -338,51 +338,45 @@ txBufferingHandler::startElement(nsIAtom
 
     txOutputTransaction* transaction =
         new txStartElementTransaction(aPrefix, aLocalName, aNsID);
     NS_ENSURE_TRUE(transaction, NS_ERROR_OUT_OF_MEMORY);
 
     return mBuffer->addTransaction(transaction);
 }
 
-static PRBool
-deleteTransaction(void* aElement, void *aData)
-{
-    delete static_cast<txOutputTransaction*>(aElement);
-    return PR_TRUE;
-}
-
 txResultBuffer::~txResultBuffer()
 {
-    mTransactions.EnumerateForwards(deleteTransaction, nsnull);
+    for (PRUint32 i, len = mTransactions.Length(); i < len; ++i) {
+        delete mTransactions[i];
+    }
 }
 
 nsresult
 txResultBuffer::addTransaction(txOutputTransaction* aTransaction)
 {
-    if (!mTransactions.AppendElement(aTransaction)) {
+    if (mTransactions.AppendElement(aTransaction) == nsnull) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
     return NS_OK;
 }
 
 struct Holder
 {
     txAXMLEventHandler** mHandler;
     nsresult mResult;
     nsAFlatString::const_char_iterator mIter;
 };
 
 static PRBool
-flushTransaction(void* aElement, void *aData)
+flushTransaction(txOutputTransaction* aElement, Holder* aData)
 {
-    Holder* holder = static_cast<Holder*>(aData);
+    Holder* holder = aData;
     txAXMLEventHandler* handler = *holder->mHandler;
-    txOutputTransaction* transaction =
-        static_cast<txOutputTransaction*>(aElement);
+    txOutputTransaction* transaction = aElement;
 
     nsresult rv;
     switch (transaction->mType) {
         case txOutputTransaction::eAttributeAtomTransaction:
         {
             txAttributeAtomTransaction* transaction =
                 static_cast<txAttributeAtomTransaction*>(aElement);
             rv = handler->attribute(transaction->mPrefix,
@@ -469,22 +463,26 @@ flushTransaction(void* aElement, void *a
 }
 
 nsresult
 txResultBuffer::flushToHandler(txAXMLEventHandler** aHandler)
 {
     Holder data = { aHandler, NS_OK };
     mStringValue.BeginReading(data.mIter);
 
-    mTransactions.EnumerateForwards(flushTransaction, &data);
+    for (PRUint32 i, len = mTransactions.Length(); i < len; ++i) {
+        if (!flushTransaction(mTransactions[i], &data)) {
+            break;
+        }
+    }
 
     return data.mResult;
 }
 
 txOutputTransaction*
 txResultBuffer::getLastTransaction()
 {
-    PRInt32 last = mTransactions.Count() - 1;
+    PRInt32 last = mTransactions.Length() - 1;
     if (last < 0) {
         return nsnull;
     }
-    return static_cast<txOutputTransaction*>(mTransactions[last]);
+    return mTransactions[last];
 }
--- a/content/xslt/src/xslt/txBufferingHandler.h
+++ b/content/xslt/src/xslt/txBufferingHandler.h
@@ -37,17 +37,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef txBufferingHandler_h__
 #define txBufferingHandler_h__
 
 #include "txXMLEventHandler.h"
 #include "nsString.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsAutoPtr.h"
 
 class txOutputTransaction;
 class txCharacterTransaction;
 
 class txResultBuffer
 {
 public:
@@ -62,17 +62,17 @@ public:
      */
     nsresult flushToHandler(txAXMLEventHandler** aHandler);
 
     txOutputTransaction* getLastTransaction();
 
     nsString mStringValue;
 
 private:
-    nsVoidArray mTransactions;
+    nsTArray<txOutputTransaction*> mTransactions;
 };
 
 class txBufferingHandler : public txAXMLEventHandler
 {
 public:
     txBufferingHandler();
 
     TX_DECL_TXAXMLEVENTHANDLER
--- a/content/xslt/src/xslt/txExecutionState.h
+++ b/content/xslt/src/xslt/txExecutionState.h
@@ -37,17 +37,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef TRANSFRMX_TXEXECUTIONSTATE_H
 #define TRANSFRMX_TXEXECUTIONSTATE_H
 
 #include "txCore.h"
 #include "txStack.h"
 #include "txXMLUtils.h"
-#include "nsVoidArray.h"
 #include "txIXPathContext.h"
 #include "txVariableMap.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 #include "txKey.h"
 #include "txStylesheet.h"
 #include "txXPathTreeWalker.h"
 #include "nsTArray.h"
--- a/content/xslt/src/xslt/txInstructions.cpp
+++ b/content/xslt/src/xslt/txInstructions.cpp
@@ -637,20 +637,20 @@ txProcessingInstruction::execute(txExecu
 
 txPushNewContext::txPushNewContext(nsAutoPtr<Expr> aSelect)
     : mSelect(aSelect), mBailTarget(nsnull)
 {
 }
 
 txPushNewContext::~txPushNewContext()
 {
-    PRInt32 i;
-    for (i = 0; i < mSortKeys.Count(); ++i)
+    PRUint32 i;
+    for (i = 0; i < mSortKeys.Length(); ++i)
     {
-        delete static_cast<SortKey*>(mSortKeys[i]);
+        delete mSortKeys[i];
     }
 }
 
 nsresult
 txPushNewContext::execute(txExecutionState& aEs)
 {
     nsRefPtr<txAExprResult> exprRes;
     nsresult rv = mSelect->evaluate(aEs.getEvalContext(),
@@ -668,19 +668,19 @@ txPushNewContext::execute(txExecutionSta
     
     if (nodes->isEmpty()) {
         aEs.gotoInstruction(mBailTarget);
         
         return NS_OK;
     }
 
     txNodeSorter sorter;
-    PRInt32 i, count = mSortKeys.Count();
+    PRUint32 i, count = mSortKeys.Length();
     for (i = 0; i < count; ++i) {
-        SortKey* sort = static_cast<SortKey*>(mSortKeys[i]);
+        SortKey* sort = mSortKeys[i];
         rv = sorter.addSortElement(sort->mSelectExpr, sort->mLangExpr,
                                    sort->mDataTypeExpr, sort->mOrderExpr,
                                    sort->mCaseOrderExpr,
                                    aEs.getEvalContext());
         NS_ENSURE_SUCCESS(rv, rv);
     }
     nsRefPtr<txNodeSet> sortedNodes;
     rv = sorter.sortNodeSet(nodes, &aEs, getter_AddRefs(sortedNodes));
@@ -706,17 +706,17 @@ txPushNewContext::addSort(nsAutoPtr<Expr
                           nsAutoPtr<Expr> aDataTypeExpr,
                           nsAutoPtr<Expr> aOrderExpr,
                           nsAutoPtr<Expr> aCaseOrderExpr)
 {
     SortKey* sort = new SortKey(aSelectExpr, aLangExpr, aDataTypeExpr,
                                 aOrderExpr, aCaseOrderExpr);
     NS_ENSURE_TRUE(sort, NS_ERROR_OUT_OF_MEMORY);
 
-    if (!mSortKeys.AppendElement(sort)) {
+    if (mSortKeys.AppendElement(sort) == nsnull) {
         delete sort;
         return NS_ERROR_OUT_OF_MEMORY;
     }
    
     return NS_OK;
 }
 
 txPushNewContext::SortKey::SortKey(nsAutoPtr<Expr> aSelectExpr,
--- a/content/xslt/src/xslt/txInstructions.h
+++ b/content/xslt/src/xslt/txInstructions.h
@@ -41,16 +41,17 @@
 
 #include "nsCOMPtr.h"
 #include "txCore.h"
 #include "nsString.h"
 #include "txXMLUtils.h"
 #include "txNamespaceMap.h"
 #include "nsAutoPtr.h"
 #include "txXSLTNumber.h"
+#include "nsTArray.h"
 
 class nsIAtom;
 class txExecutionState;
 
 class txInstruction : public TxObject
 {
 public:
     txInstruction()
@@ -299,17 +300,17 @@ public:
 
         nsAutoPtr<Expr> mSelectExpr;
         nsAutoPtr<Expr> mLangExpr;
         nsAutoPtr<Expr> mDataTypeExpr;
         nsAutoPtr<Expr> mOrderExpr;
         nsAutoPtr<Expr> mCaseOrderExpr;
     };
     
-    nsVoidArray mSortKeys;
+    nsTArray<SortKey*> mSortKeys;
     nsAutoPtr<Expr> mSelect;
     txInstruction* mBailTarget;
 };
 
 class txPushNullTemplateRule : public txInstruction
 {
 public:
     TX_DECL_TXINSTRUCTION
--- a/content/xslt/src/xslt/txStylesheetCompiler.cpp
+++ b/content/xslt/src/xslt/txStylesheetCompiler.cpp
@@ -224,18 +224,18 @@ txStylesheetCompiler::startElementIntern
                                            nsIAtom* aLocalName,
                                            nsIAtom* aPrefix,
                                            txStylesheetAttr* aAttributes,
                                            PRInt32 aAttrCount,
                                            PRInt32 aIDOffset)
 {
     nsresult rv = NS_OK;
     PRInt32 i;
-    for (i = mInScopeVariables.Count() - 1; i >= 0; --i) {
-        ++(static_cast<txInScopeVariable*>(mInScopeVariables[i]))->mLevel;
+    for (i = mInScopeVariables.Length() - 1; i >= 0; --i) {
+        ++mInScopeVariables[i]->mLevel;
     }
 
     // Update the elementcontext if we have special attributes
     for (i = 0; i < aAttrCount; ++i) {
         txStylesheetAttr* attr = aAttributes + i;
 
         // xml:space
         if (attr->mNamespaceID == kNameSpaceID_XML &&
@@ -282,17 +282,17 @@ txStylesheetCompiler::startElementIntern
             while (tok.hasMoreTokens()) {
                 PRInt32 namespaceID = mElementContext->mMappings->
                     lookupNamespaceWithDefault(tok.nextToken());
                 
                 if (namespaceID == kNameSpaceID_Unknown)
                     return NS_ERROR_XSLT_PARSE_FAILURE;
 
                 if (!mElementContext->mInstructionNamespaces.
-                        AppendElement(NS_INT32_TO_PTR(namespaceID))) {
+                        AppendElement(namespaceID)) {
                     return NS_ERROR_OUT_OF_MEMORY;
                 }
             }
 
             attr->mLocalName = nsnull;
         }
 
         // version
@@ -313,20 +313,19 @@ txStylesheetCompiler::startElementIntern
             else {
                 mElementContext->mForwardsCompatibleParsing = MB_TRUE;
             }
         }
     }
 
     // Find the right elementhandler and execute it
     MBool isInstruction = MB_FALSE;
-    PRInt32 count = mElementContext->mInstructionNamespaces.Count();
+    PRInt32 count = mElementContext->mInstructionNamespaces.Length();
     for (i = 0; i < count; ++i) {
-        if (NS_PTR_TO_INT32(mElementContext->mInstructionNamespaces[i]) ==
-            aNamespaceID) {
+        if (mElementContext->mInstructionNamespaces[i] == aNamespaceID) {
             isInstruction = MB_TRUE;
             break;
         }
     }
 
     if (mEmbedStatus == eNeedEmbed) {
         // handle embedded stylesheets
         if (aIDOffset >= 0 && aAttributes[aIDOffset].mValue.Equals(mTarget)) {
@@ -376,19 +375,18 @@ txStylesheetCompiler::endElement()
         // XXX reevaluate once expat stops on failure
         return NS_OK;
     }
 
     nsresult rv = flushCharacters();
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRInt32 i;
-    for (i = mInScopeVariables.Count() - 1; i >= 0; --i) {
-        txInScopeVariable* var =
-            static_cast<txInScopeVariable*>(mInScopeVariables[i]);
+    for (i = mInScopeVariables.Length() - 1; i >= 0; --i) {
+        txInScopeVariable* var = mInScopeVariables[i];
         if (!--(var->mLevel)) {
             nsAutoPtr<txInstruction> instr(new txRemoveVariable(var->mName));
             NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY);
 
             rv = addInstruction(instr);
             NS_ENSURE_SUCCESS(rv, rv);
             
             mInScopeVariables.RemoveElementAt(i);
@@ -539,17 +537,17 @@ txStylesheetCompiler::ensureNewElementCo
     mElementContext = context;
 
     return NS_OK;
 }
 
 nsresult
 txStylesheetCompiler::maybeDoneCompiling()
 {
-    if (!mDoneWithThisStylesheet || mChildCompilerList.Count()) {
+    if (!mDoneWithThisStylesheet || !mChildCompilerList.IsEmpty()) {
         return NS_OK;
     }
     
     if (mIsTopCompiler) {
         nsresult rv = mStylesheet->doneCompiling();
         if (NS_FAILED(rv)) {
             cancel(rv);
             return rv;
@@ -642,18 +640,18 @@ txStylesheetCompilerState::init(const ns
 
 txStylesheetCompilerState::~txStylesheetCompilerState()
 {
     while (!mObjectStack.isEmpty()) {
         delete popObject();
     }
     
     PRInt32 i;
-    for (i = mInScopeVariables.Count() - 1; i >= 0; --i) {
-        delete static_cast<txInScopeVariable*>(mInScopeVariables[i]);
+    for (i = mInScopeVariables.Length() - 1; i >= 0; --i) {
+        delete mInScopeVariables[i];
     }
 }
 
 nsresult
 txStylesheetCompilerState::pushHandlerTable(txHandlerTable* aTable)
 {
     nsresult rv = pushPtr(mHandlerTable);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -750,34 +748,34 @@ txStylesheetCompilerState::openInstructi
 
     mNextInstrPtr = aContainer->mFirstInstruction.StartAssignment();
     return NS_OK;
 }
 
 void
 txStylesheetCompilerState::closeInstructionContainer()
 {
-    NS_ASSERTION(mGotoTargetPointers.Count() == 0,
+    NS_ASSERTION(mGotoTargetPointers.IsEmpty(),
                  "GotoTargets still exists, did you forget to add txReturn?");
     mNextInstrPtr = 0;
 }
 
 nsresult
 txStylesheetCompilerState::addInstruction(nsAutoPtr<txInstruction> aInstruction)
 {
     NS_PRECONDITION(mNextInstrPtr, "adding instruction outside container");
 
     txInstruction* newInstr = aInstruction;
 
     *mNextInstrPtr = aInstruction.forget();
     mNextInstrPtr = newInstr->mNext.StartAssignment();
     
-    PRInt32 i, count = mGotoTargetPointers.Count();
+    PRUint32 i, count = mGotoTargetPointers.Length();
     for (i = 0; i < count; ++i) {
-        *static_cast<txInstruction**>(mGotoTargetPointers[i]) = newInstr;
+        *mGotoTargetPointers[i] = newInstr;
     }
     mGotoTargetPointers.Clear();
 
     return NS_OK;
 }
 
 nsresult
 txStylesheetCompilerState::loadIncludedStylesheet(const nsAString& aURI)
@@ -806,17 +804,17 @@ txStylesheetCompilerState::loadIncludedS
     nsRefPtr<txStylesheetCompiler> compiler =
         new txStylesheetCompiler(aURI, mStylesheet, &mToplevelIterator,
                                  observer);
     NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
 
     // step forward before calling the observer in case of syncronous loading
     mToplevelIterator.next();
 
-    if (!mChildCompilerList.AppendElement(compiler)) {
+    if (mChildCompilerList.AppendElement(compiler) == nsnull) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
     rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
     if (NS_FAILED(rv)) {
         mChildCompilerList.RemoveElement(compiler);
     }
 
@@ -839,32 +837,32 @@ txStylesheetCompilerState::loadImportedS
     iter.next(); // go to the end of the list
 
     txACompileObserver* observer = static_cast<txStylesheetCompiler*>(this);
 
     nsRefPtr<txStylesheetCompiler> compiler =
         new txStylesheetCompiler(aURI, mStylesheet, &iter, observer);
     NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
 
-    if (!mChildCompilerList.AppendElement(compiler)) {
+    if (mChildCompilerList.AppendElement(compiler) == nsnull) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
     nsresult rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
     if (NS_FAILED(rv)) {
         mChildCompilerList.RemoveElement(compiler);
     }
 
     return rv;  
 }
 
 nsresult
 txStylesheetCompilerState::addGotoTarget(txInstruction** aTargetPointer)
 {
-    if (!mGotoTargetPointers.AppendElement(aTargetPointer)) {
+    if (mGotoTargetPointers.AppendElement(aTargetPointer) == nsnull) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
     
     return NS_OK;
 }
 
 nsresult
 txStylesheetCompilerState::addVariable(const txExpandedName& aName)
@@ -1157,17 +1155,17 @@ txStylesheetCompilerState::shutdown()
 
 txElementContext::txElementContext(const nsAString& aBaseURI)
     : mPreserveWhitespace(PR_FALSE),
       mForwardsCompatibleParsing(PR_TRUE),
       mBaseURI(aBaseURI),
       mMappings(new txNamespaceMap),
       mDepth(0)
 {
-    mInstructionNamespaces.AppendElement(NS_INT32_TO_PTR(kNameSpaceID_XSLT));
+    mInstructionNamespaces.AppendElement(kNameSpaceID_XSLT);
 }
 
 txElementContext::txElementContext(const txElementContext& aOther)
     : mPreserveWhitespace(aOther.mPreserveWhitespace),
       mForwardsCompatibleParsing(aOther.mForwardsCompatibleParsing),
       mBaseURI(aOther.mBaseURI),
       mMappings(aOther.mMappings),
       mDepth(0)
--- a/content/xslt/src/xslt/txStylesheetCompiler.h
+++ b/content/xslt/src/xslt/txStylesheetCompiler.h
@@ -40,40 +40,42 @@
 #define TRANSFRMX_TXSTYLESHEETCOMPILER_H
 
 #include "txStack.h"
 #include "txXSLTPatterns.h"
 #include "txExpr.h"
 #include "txIXPathContext.h"
 #include "nsAutoPtr.h"
 #include "txStylesheet.h"
+#include "nsTArray.h"
 
 extern PRBool
 TX_XSLTFunctionAvailable(nsIAtom* aName, PRInt32 aNameSpaceID);
 
 class txHandlerTable;
 class txElementContext;
 class txInstructionContainer;
 class txInstruction;
 class txNamespaceMap;
 class txToplevelItem;
 class txPushNewContext;
 class txStylesheetCompiler;
+class txInScopeVariable;
 
 class txElementContext : public TxObject
 {
 public:
     txElementContext(const nsAString& aBaseURI);
     txElementContext(const txElementContext& aOther);
 
     PRBool mPreserveWhitespace;
     PRBool mForwardsCompatibleParsing;
     nsString mBaseURI;
     nsRefPtr<txNamespaceMap> mMappings;
-    nsVoidArray mInstructionNamespaces;
+    nsTArray<PRInt32> mInstructionNamespaces;
     PRInt32 mDepth;
 };
 
 class txACompileObserver
 {
 public:
     virtual nsrefcnt AddRef() = 0;
     virtual nsrefcnt Release() = 0;
@@ -164,18 +166,18 @@ public:
     nsAutoPtr<txElementContext> mElementContext;
     txPushNewContext* mSorter;
     nsAutoPtr<txList> mChooseGotoList;
     PRPackedBool mDOE;
     PRPackedBool mSearchingForFallback;
 
 protected:
     nsRefPtr<txACompileObserver> mObserver;
-    nsVoidArray mInScopeVariables;
-    nsVoidArray mChildCompilerList;
+    nsTArray<txInScopeVariable*> mInScopeVariables;
+    nsTArray<txStylesheetCompiler*> mChildCompilerList;
     // embed info, target information is the ID
     nsString mTarget;
     enum 
     {
         eNoEmbed,
         eNeedEmbed,
         eInEmbed,
         eHasEmbed
@@ -184,17 +186,17 @@ protected:
     PRPackedBool mIsTopCompiler;
     PRPackedBool mDoneWithThisStylesheet;
     txStack mObjectStack;
     txStack mOtherStack;
 
 private:
     txInstruction** mNextInstrPtr;
     txListIterator mToplevelIterator;
-    nsVoidArray mGotoTargetPointers;
+    nsTArray<txInstruction**> mGotoTargetPointers;
 };
 
 struct txStylesheetAttr
 {
     PRInt32 mNamespaceID;
     nsCOMPtr<nsIAtom> mLocalName;
     nsCOMPtr<nsIAtom> mPrefix;
     nsString mValue;
--- a/content/xslt/src/xslt/txXSLTPatterns.h
+++ b/content/xslt/src/xslt/txXSLTPatterns.h
@@ -36,17 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef TX_XSLT_PATTERNS_H
 #define TX_XSLT_PATTERNS_H
 
 #include "txExpr.h"
 #include "txXMLUtils.h"
-#include "nsVoidArray.h"
 
 class ProcessorState;
 
 class txPattern
 {
 public:
     txPattern()
     {
--- a/content/xul/document/src/nsXULContentSink.h
+++ b/content/xul/document/src/nsXULContentSink.h
@@ -41,17 +41,16 @@
 
 #ifndef nsXULContentSink_h__
 #define nsXULContentSink_h__
 
 #include "nsIExpatSink.h"
 #include "nsIXMLContentSink.h"
 #include "nsAutoPtr.h"
 #include "nsNodeInfoManager.h"
-#include "nsVoidArray.h"
 #include "nsWeakPtr.h"
 #include "nsXULElement.h"
 
 class nsIDocument;
 class nsIScriptSecurityManager;
 class nsAttrName;
 class nsXULPrototypeDocument;
 class nsXULPrototypeElement;
--- a/content/xul/document/src/nsXULControllers.cpp
+++ b/content/xul/document/src/nsXULControllers.cpp
@@ -62,20 +62,20 @@ nsXULControllers::nsXULControllers()
 nsXULControllers::~nsXULControllers(void)
 {
   DeleteControllers();
 }
 
 void
 nsXULControllers::DeleteControllers()
 {
-  PRUint32 count = mControllers.Count();
+  PRUint32 count = mControllers.Length();
   for (PRUint32 i = 0; i < count; i++)
   {
-    nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.ElementAt(i));
+    nsXULControllerData* controllerData = mControllers.ElementAt(i);
     if (controllerData)
       delete controllerData;    // releases the nsIController
   }
   
   mControllers.Clear();
 }
 
 
@@ -98,20 +98,19 @@ NS_NewXULControllers(nsISupports* aOuter
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULControllers)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULControllers)
   tmp->DeleteControllers();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULControllers)
   {
-    PRUint32 i, count = tmp->mControllers.Count();
+    PRUint32 i, count = tmp->mControllers.Length();
     for (i = 0; i < count; ++i) {
-      nsXULControllerData*  controllerData =
-        static_cast<nsXULControllerData*>(tmp->mControllers[i]);
+      nsXULControllerData* controllerData = tmp->mControllers[i];
       if (controllerData) {
         cb.NoteXPCOMChild(controllerData->mController);
       }
     }
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULControllers)
@@ -125,20 +124,20 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOU
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXULControllers, nsIControllers)
 
 NS_IMETHODIMP
 nsXULControllers::GetControllerForCommand(const char *aCommand, nsIController** _retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nsnull;
 
-  PRUint32 count = mControllers.Count();
+  PRUint32 count = mControllers.Length();
   for (PRUint32 i=0; i < count; i++)
   {
-    nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.ElementAt(i));
+    nsXULControllerData* controllerData = mControllers.ElementAt(i);
     if (controllerData)
     {
       nsCOMPtr<nsIController> controller;
       controllerData->GetController(getter_AddRefs(controller));
       if (controller)
       {
         PRBool supportsCommand;
         controller->SupportsCommand(aCommand, &supportsCommand);
@@ -155,82 +154,78 @@ nsXULControllers::GetControllerForComman
 }
 
 NS_IMETHODIMP
 nsXULControllers::InsertControllerAt(PRUint32 aIndex, nsIController *controller)
 {
   nsXULControllerData*  controllerData = new nsXULControllerData(++mCurControllerID, controller);
   if (!controllerData) return NS_ERROR_OUT_OF_MEMORY;
 #ifdef DEBUG
-  PRBool inserted =
+  nsXULControllerData** inserted =
 #endif
-  mControllers.InsertElementAt((void *)controllerData, aIndex);
-  NS_ASSERTION(inserted, "Insertion of controller failed");
+  mControllers.InsertElementAt(aIndex, controllerData);
+  NS_ASSERTION(inserted != nsnull, "Insertion of controller failed");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULControllers::RemoveControllerAt(PRUint32 aIndex, nsIController **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nsnull;
 
-  nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.SafeElementAt(aIndex));
+  nsXULControllerData* controllerData = mControllers.SafeElementAt(aIndex);
   if (!controllerData) return NS_ERROR_FAILURE;
 
-#ifdef DEBUG
-  PRBool removed =
-#endif
   mControllers.RemoveElementAt(aIndex);
-  NS_ASSERTION(removed, "Removal of controller failed");
 
   controllerData->GetController(_retval);
   delete controllerData;
   
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsXULControllers::GetControllerAt(PRUint32 aIndex, nsIController **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nsnull;
 
-  nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.SafeElementAt(aIndex));
+  nsXULControllerData* controllerData = mControllers.SafeElementAt(aIndex);
   if (!controllerData) return NS_ERROR_FAILURE;
 
   return controllerData->GetController(_retval);   // does the addref  
 }
 
 NS_IMETHODIMP
 nsXULControllers::AppendController(nsIController *controller)
 {
   // This assigns controller IDs starting at 1 so we can use 0 to test if an ID was obtained
   nsXULControllerData*  controllerData = new nsXULControllerData(++mCurControllerID, controller);
   if (!controllerData) return NS_ERROR_OUT_OF_MEMORY;
 
 #ifdef DEBUG
-  PRBool appended =
+  nsXULControllerData** appended =
 #endif
-  mControllers.AppendElement((void *)controllerData);
-  NS_ASSERTION(appended, "Appending controller failed");
+  mControllers.AppendElement(controllerData);
+  NS_ASSERTION(appended != nsnull, "Appending controller failed");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULControllers::RemoveController(nsIController *controller)
 {
   // first get the identity pointer
   nsCOMPtr<nsISupports> controllerSup(do_QueryInterface(controller));
   // then find it
-  PRUint32 count = mControllers.Count();
+  PRUint32 count = mControllers.Length();
   for (PRUint32 i = 0; i < count; i++)
   {
-    nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.ElementAt(i));
+    nsXULControllerData* controllerData = mControllers.ElementAt(i);
     if (controllerData)
     {
       nsCOMPtr<nsIController> thisController;
       controllerData->GetController(getter_AddRefs(thisController));
       nsCOMPtr<nsISupports> thisControllerSup(do_QueryInterface(thisController)); // get identity
       if (thisControllerSup == controllerSup)
       {
         mControllers.RemoveElementAt(i);
@@ -243,20 +238,20 @@ nsXULControllers::RemoveController(nsICo
 }
     
 /* unsigned long getControllerId (in nsIController controller); */
 NS_IMETHODIMP
 nsXULControllers::GetControllerId(nsIController *controller, PRUint32 *_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
 
-  PRUint32 count = mControllers.Count();
+  PRUint32 count = mControllers.Length();
   for (PRUint32 i = 0; i < count; i++)
   {
-    nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.ElementAt(i));
+    nsXULControllerData* controllerData = mControllers.ElementAt(i);
     if (controllerData)
     {
       nsCOMPtr<nsIController> thisController;
       controllerData->GetController(getter_AddRefs(thisController));
       if (thisController.get() == controller)
       {
         *_retval = controllerData->GetControllerID();
         return NS_OK;
@@ -267,33 +262,33 @@ nsXULControllers::GetControllerId(nsICon
 }
 
 /* nsIController getControllerById (in unsigned long controllerID); */
 NS_IMETHODIMP
 nsXULControllers::GetControllerById(PRUint32 controllerID, nsIController **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
     
-  PRUint32 count = mControllers.Count();
+  PRUint32 count = mControllers.Length();
   for (PRUint32 i = 0; i < count; i++)
   {
-    nsXULControllerData*  controllerData = static_cast<nsXULControllerData*>(mControllers.ElementAt(i));
+    nsXULControllerData* controllerData = mControllers.ElementAt(i);
     if (controllerData && controllerData->GetControllerID() == controllerID)
     {
       return controllerData->GetController(_retval);
     }
   }
   return NS_ERROR_FAILURE;  // none found
 }
 
 NS_IMETHODIMP
 nsXULControllers::GetControllerCount(PRUint32 *_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
-  *_retval = mControllers.Count();
+  *_retval = mControllers.Length();
   return NS_OK;
 }
 
 // nsISecurityCheckedComponent implementation
 
 static char* cloneAllAccess()
 {
   static const char allAccess[] = "AllAccess";
--- a/content/xul/document/src/nsXULControllers.h
+++ b/content/xul/document/src/nsXULControllers.h
@@ -41,17 +41,17 @@
   The XUL "controllers" object.
 
 */
 
 #ifndef nsXULControllers_h__
 #define nsXULControllers_h__
 
 #include "nsCOMPtr.h"
-#include "nsVoidArray.h"
+#include "nsTPtrArray.h"
 #include "nsWeakPtr.h"
 #include "nsIControllers.h"
 #include "nsISecurityCheckedComponent.h"
 #include "nsCycleCollectionParticipant.h"
 
 /* non-XPCOM class for holding controllers and their IDs */
 class nsXULControllerData
 {
@@ -92,16 +92,16 @@ public:
     NS_DECL_NSISECURITYCHECKEDCOMPONENT
   
 protected:
     nsXULControllers();
     virtual ~nsXULControllers(void);
 
     void        DeleteControllers();
 
-    nsVoidArray mControllers;
-    PRUint32    mCurControllerID;
+    nsTPtrArray<nsXULControllerData> mControllers;
+    PRUint32                         mCurControllerID;
 };
 
 
 
 
 #endif // nsXULControllers_h__
--- a/content/xul/templates/src/nsTemplateRule.h
+++ b/content/xul/templates/src/nsTemplateRule.h
@@ -40,17 +40,16 @@
 #define nsTemplateRule_h__
 
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIRDFDataSource.h"
 #include "nsIRDFResource.h"
 #include "nsIContent.h"
 #include "nsIDOMNode.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsIXULTemplateRuleFilter.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsIXULTemplateQueryProcessor;
 class nsTemplateQuerySet;
 
@@ -272,17 +271,17 @@ protected:
  *  explicit <queryset> tag or implied if the tag is not used.
  *
  *  These queryset objects are created and owned by the builder in its
  *  mQuerySets array.
  */
 class nsTemplateQuerySet
 {
 protected:
-    nsVoidArray mRules; // rules owned by nsTemplateQuerySet
+    nsTArray<nsTemplateRule*> mRules; // rules owned by nsTemplateQuerySet
 
     // a number which increments for each successive queryset. It is stored so
     // it can be used as an optimization when updating results so that it is
     // known where to insert them into a match.
     PRInt32 mPriority;
 
 public:
 
@@ -316,37 +315,37 @@ public:
 
     nsIAtom* GetTag() { return mTag; }
     void SetTag(nsIAtom* aTag) { mTag = aTag; }
 
     nsresult AddRule(nsTemplateRule *aChild)
     {
         // nsTemplateMatch stores the index as a 16-bit value,
         // so check to make sure for overflow
-        if (mRules.Count() == PR_INT16_MAX)
+        if (mRules.Length() == PR_INT16_MAX)
             return NS_ERROR_FAILURE;
 
-        if (!mRules.AppendElement(aChild))
+        if (mRules.AppendElement(aChild) == nsnull)
             return NS_ERROR_OUT_OF_MEMORY;
         return NS_OK;
     }
 
     PRInt16 RuleCount() const
     {
-        return mRules.Count();
+        return mRules.Length();
     }
 
     nsTemplateRule* GetRuleAt(PRInt16 aIndex)
     {
-        return static_cast<nsTemplateRule*>(mRules[aIndex]);
+        return mRules[aIndex];
     }
 
     void Clear()
     {
-        for (PRInt32 r = mRules.Count() - 1; r >= 0; r--) {
-            nsTemplateRule* rule = static_cast<nsTemplateRule*>(mRules[r]);
+        for (PRInt32 r = mRules.Length() - 1; r >= 0; r--) {
+            nsTemplateRule* rule = mRules[r];
             delete rule;
         }
         mRules.Clear();
     }
 };
 
 #endif // nsTemplateRule_h__
--- a/content/xul/templates/src/nsXULContentBuilder.cpp
+++ b/content/xul/templates/src/nsXULContentBuilder.cpp
@@ -49,17 +49,17 @@
 #include "nsIXULDocument.h"
 
 #include "nsContentSupportMap.h"
 #include "nsRDFConMemberTestNode.h"
 #include "nsRDFPropertyTestNode.h"
 #include "nsXULSortService.h"
 #include "nsTemplateRule.h"
 #include "nsTemplateMap.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsXPIDLString.h"
 #include "nsGkAtoms.h"
 #include "nsXULContentUtils.h"
 #include "nsXULElement.h"
 #include "nsXULTemplateBuilder.h"
 #include "nsSupportsArray.h"
 #include "nsNodeInfoManager.h"
 #include "nsContentCreatorFunctions.h"
@@ -1318,25 +1318,25 @@ nsXULContentBuilder::IsOpen(nsIContent* 
     return PR_TRUE;
 }
 
 nsresult
 nsXULContentBuilder::RemoveGeneratedContent(nsIContent* aElement)
 {
     // Keep a queue of "ungenerated" elements that we have to probe
     // for generated content.
-    nsAutoVoidArray ungenerated;
-    if (!ungenerated.AppendElement(aElement))
+    nsAutoTArray<nsIContent*, 8> ungenerated;
+    if (ungenerated.AppendElement(aElement) == nsnull)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    PRInt32 count;
-    while (0 != (count = ungenerated.Count())) {
+    PRUint32 count;
+    while (0 != (count = ungenerated.Length())) {
         // Pull the next "ungenerated" element off the queue.
-        PRInt32 last = count - 1;
-        nsIContent* element = static_cast<nsIContent*>(ungenerated[last]);
+        PRUint32 last = count - 1;
+        nsIContent* element = ungenerated[last];
         ungenerated.RemoveElementAt(last);
 
         PRUint32 i = element->GetChildCount();
 
         while (i-- > 0) {
             nsCOMPtr<nsIContent> child = element->GetChildAt(i);
 
             // Optimize for the <template> element, because we *know*
@@ -1352,17 +1352,17 @@ nsXULContentBuilder::RemoveGeneratedCont
             // If the element is in the template map, then we
             // assume it's been generated and nuke it.
             nsCOMPtr<nsIContent> tmpl;
             mTemplateMap.GetTemplateFor(child, getter_AddRefs(tmpl));
 
             if (! tmpl) {
                 // No 'template' attribute, so this must not have been
                 // generated. We'll need to examine its kids.
-                if (!ungenerated.AppendElement(child))
+                if (ungenerated.AppendElement(child) == nsnull)
                     return NS_ERROR_OUT_OF_MEMORY;
                 continue;
             }
 
             // If we get here, it's "generated". Bye bye!
             element->RemoveChildAt(i, PR_TRUE);
 
             // Remove this and any children from the content support map.
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -84,17 +84,17 @@
 #include "nsISimpleEnumerator.h"
 #include "nsIMutableArray.h"
 #include "nsIURL.h"
 #include "nsIXPConnect.h"
 #include "nsContentCID.h"
 #include "nsRDFCID.h"
 #include "nsXULContentUtils.h"
 #include "nsString.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsXPIDLString.h"
 #include "nsWhitespaceTokenizer.h"
 #include "nsGkAtoms.h"
 #include "nsXULElement.h"
 #include "jsapi.h"
 #include "prlog.h"
 #include "rdf.h"
 #include "pldhash.h"
@@ -2483,25 +2483,25 @@ nsXULTemplateBuilder::CompileBinding(nsT
 
 nsresult
 nsXULTemplateBuilder::AddSimpleRuleBindings(nsTemplateRule* aRule,
                                             nsIContent* aElement)
 {
     // Crawl the content tree of a "simple" rule, adding a variable
     // assignment for any attribute whose value is "rdf:".
 
-    nsAutoVoidArray elements;
-
-    if (!elements.AppendElement(aElement))
+    nsAutoTArray<nsIContent*, 8> elements;
+
+    if (elements.AppendElement(aElement) == nsnull)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    while (elements.Count()) {
+    while (elements.Length()) {
         // Pop the next element off the stack
-        PRUint32 i = (PRUint32)(elements.Count() - 1);
-        nsIContent* element = static_cast<nsIContent*>(elements[i]);
+        PRUint32 i = elements.Length() - 1;
+        nsIContent* element = elements[i];
         elements.RemoveElementAt(i);
 
         // Iterate through its attributes, looking for substitutions
         // that we need to add as bindings.
         PRUint32 count = element->GetAttrCount();
 
         for (i = 0; i < count; ++i) {
             const nsAttrName* name = element->GetAttrNameAt(i);
@@ -2516,17 +2516,17 @@ nsXULTemplateBuilder::AddSimpleRuleBindi
                 ParseAttribute(value, AddBindingsFor, nsnull, aRule);
             }
         }
 
         // Push kids onto the stack, and search them next.
         count = element->GetChildCount();
 
         while (count-- > 0) {
-            if (!elements.AppendElement(element->GetChildAt(count)))
+            if (elements.AppendElement(element->GetChildAt(count)) == nsnull)
                 return NS_ERROR_OUT_OF_MEMORY;
         }
     }
 
     aRule->AddBindingsToQueryProcessor(mQueryProcessor);
 
     return NS_OK;
 }
--- a/content/xul/templates/src/nsXULTemplateBuilder.h
+++ b/content/xul/templates/src/nsXULTemplateBuilder.h
@@ -51,17 +51,16 @@
 #include "nsIRDFContainer.h"
 #include "nsIRDFContainerUtils.h"
 #include "nsIRDFDataSource.h"
 #include "nsIRDFObserver.h"
 #include "nsIRDFService.h"
 #include "nsIXULTemplateBuilder.h"
 
 #include "nsFixedSizeAllocator.h"
-#include "nsVoidArray.h"
 #include "nsCOMArray.h"
 #include "nsTArray.h"
 #include "nsDataHashtable.h"
 #include "nsTemplateRule.h"
 #include "nsTemplateMatch.h"
 #include "nsIXULTemplateQueryProcessor.h"
 #include "nsCycleCollectionParticipant.h"
 
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h
@@ -56,17 +56,16 @@
 #include "nsCollationCID.h"
 
 #include "nsFixedSizeAllocator.h"
 #include "nsResourceSet.h"
 #include "nsRuleNetwork.h"
 #include "nsRDFQuery.h"
 #include "nsRDFBinding.h"
 #include "nsXULTemplateResultSetRDF.h"
-#include "nsVoidArray.h"
 #include "nsCOMArray.h"
 #include "nsIArray.h"
 #include "nsString.h"
 #include "nsClassHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "prlog.h"
--- a/content/xul/templates/src/nsXULTreeBuilder.cpp
+++ b/content/xul/templates/src/nsXULTreeBuilder.cpp
@@ -54,17 +54,17 @@
 #include "nsReadableUtils.h"
 #include "nsQuickSort.h"
 #include "nsTreeRows.h"
 #include "nsTemplateRule.h"
 #include "nsTemplateMatch.h"
 #include "nsGkAtoms.h"
 #include "nsXULContentUtils.h"
 #include "nsXULTemplateBuilder.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsUnicharUtils.h"
 #include "nsINameSpaceManager.h"
 #include "nsIDOMClassInfo.h"
 
 // For security check
 #include "nsIDocument.h"
 
 /**
@@ -147,17 +147,17 @@ protected:
                   PRInt32* aDelta);
 
     nsresult
     OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
                            PRInt32 aIndex,
                            nsIXULTemplateResult *aResult,
                            nsTemplateQuerySet* aQuerySet,
                            PRInt32* aDelta,
-                           nsAutoVoidArray& open);
+                           nsTArray<PRInt32>& open);
 
     /**
      * Close a container row, removing the container's childrem from
      * the view.
      */
     nsresult
     CloseContainer(PRInt32 aIndex);
 
@@ -1517,30 +1517,30 @@ nsXULTreeBuilder::OpenContainer(PRInt32 
 }
 
 nsresult
 nsXULTreeBuilder::OpenSubtreeOf(nsTreeRows::Subtree* aSubtree,
                                 PRInt32 aIndex,
                                 nsIXULTemplateResult *aResult,
                                 PRInt32* aDelta)
 {
-    nsAutoVoidArray open;
+    nsAutoTArray<PRInt32, 8> open;
     PRInt32 count = 0;
 
     PRInt32 rulecount = mQuerySets.Length();
 
     for (PRInt32 r = 0; r < rulecount; r++) {
         nsTemplateQuerySet* queryset = mQuerySets[r];
         OpenSubtreeForQuerySet(aSubtree, aIndex, aResult, queryset, &count, open);
     }
 
     // Now recursively deal with any open sub-containers that just got
     // inserted. We need to do this back-to-front to avoid skewing offsets.
-    for (PRInt32 i = open.Count() - 1; i >= 0; --i) {
-        PRInt32 index = NS_PTR_TO_INT32(open[i]);
+    for (PRInt32 i = open.Length() - 1; i >= 0; --i) {
+        PRInt32 index = open[i];
 
         nsTreeRows::Subtree* child =
             mRows.EnsureSubtreeFor(aSubtree, index);
 
         nsIXULTemplateResult* result = (*aSubtree)[index].mMatch->mResult;
 
         PRInt32 delta;
         OpenSubtreeOf(child, aIndex + index, result, &delta);
@@ -1561,17 +1561,17 @@ nsXULTreeBuilder::OpenSubtreeOf(nsTreeRo
 }
 
 nsresult
 nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
                                          PRInt32 aIndex,
                                          nsIXULTemplateResult* aResult,
                                          nsTemplateQuerySet* aQuerySet,
                                          PRInt32* aDelta,
-                                         nsAutoVoidArray& open)
+                                         nsTArray<PRInt32>& open)
 {
     PRInt32 count = *aDelta;
     
     nsCOMPtr<nsISimpleEnumerator> results;
     nsresult rv = mQueryProcessor->GenerateResults(mDataSource, aResult,
                                                    aQuerySet->mCompiledQuery,
                                                    getter_AddRefs(results));
     if (NS_FAILED(rv))
@@ -1669,17 +1669,17 @@ nsXULTreeBuilder::OpenSubtreeForQuerySet
                 // Remember that this match applied to this row
                 mRows.InsertRowAt(newmatch, aSubtree, count);
 
                 // If this is open, then remember it so we can recursively add
                 // *its* rows to the tree.
                 PRBool isOpen = PR_FALSE;
                 IsContainerOpen(nextresult, &isOpen);
                 if (isOpen) {
-                    if (!open.AppendElement(NS_INT32_TO_PTR(count)))
+                    if (open.AppendElement(count) == nsnull)
                         return NS_ERROR_OUT_OF_MEMORY;
                 }
 
                 ++count;
             }
         }
 
         if (prevmatch) {