Bug 677661 - Remove nsTPtrArray and add a SafeElementAt(index_type) API to nsTArray when it's instantiated with a pointer type; r=sicking
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 10 Aug 2011 01:36:00 -0400
changeset 74167 89bbee4ec270fadde04578b2b8765a588535e0fc
parent 74166 b391327ee19af7438cc6b4d70f3ad1c9a9d8e634
child 74168 f95d2c738d5254cfd16fae4b8115478b2138b0af
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewerssicking
bugs677661
milestone8.0a1
Bug 677661 - Remove nsTPtrArray and add a SafeElementAt(index_type) API to nsTArray when it's instantiated with a pointer type; r=sicking
accessible/src/base/nsTextAttrs.cpp
accessible/src/base/nsTextAttrs.h
content/base/src/nsAttrValue.cpp
content/base/src/nsAttrValue.h
content/base/src/nsContentUtils.cpp
content/base/src/nsGenericElement.cpp
content/html/content/src/nsHTMLFieldSetElement.h
content/xslt/src/base/txOwningArray.h
content/xslt/src/xslt/txStylesheet.cpp
content/xslt/src/xslt/txStylesheet.h
content/xslt/src/xslt/txToplevelItems.h
content/xul/document/src/nsXULControllers.h
dom/base/nsFocusManager.cpp
dom/system/nsDeviceMotion.cpp
dom/system/nsDeviceMotion.h
layout/tables/nsCellMap.cpp
layout/tables/nsCellMap.h
layout/tables/nsTableFrame.h
widget/src/windows/nsDataObj.h
xpcom/base/nsCycleCollector.cpp
xpcom/build/XPCOM.h
xpcom/glue/Makefile.in
xpcom/glue/nsTArray.h
xpcom/glue/nsTPtrArray.h
xpcom/tests/TestTArray.cpp
--- a/accessible/src/base/nsTextAttrs.cpp
+++ b/accessible/src/base/nsTextAttrs.cpp
@@ -142,17 +142,17 @@ nsTextAttrsMgr::GetAttributes(nsIPersist
   nsIContent *offsetNode = nsnull, *offsetElm = nsnull;
   nsIFrame *frame = nsnull;
   if (mOffsetAcc) {
     offsetNode = mOffsetAcc->GetContent();
     offsetElm = nsCoreUtils::GetDOMElementFor(offsetNode);
     frame = offsetElm->GetPrimaryFrame();
   }
 
-  nsTPtrArray<nsITextAttr> textAttrArray(10);
+  nsTArray<nsITextAttr*> textAttrArray(10);
 
   // "language" text attribute
   nsLangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
   textAttrArray.AppendElement(static_cast<nsITextAttr*>(&langTextAttr));
 
   // "color" text attribute
   nsCSSTextAttr colorTextAttr(0, hyperTextElm, offsetElm);
   textAttrArray.AppendElement(static_cast<nsITextAttr*>(&colorTextAttr));
@@ -207,17 +207,17 @@ nsTextAttrsMgr::GetAttributes(nsIPersist
   if (mOffsetAcc)
     rv = GetRange(textAttrArray, aStartHTOffset, aEndHTOffset);
 
   textAttrArray.Clear();
   return rv;
 }
 
 nsresult
-nsTextAttrsMgr::GetRange(const nsTPtrArray<nsITextAttr>& aTextAttrArray,
+nsTextAttrsMgr::GetRange(const nsTArray<nsITextAttr*>& aTextAttrArray,
                          PRInt32 *aStartHTOffset, PRInt32 *aEndHTOffset)
 {
   PRUint32 attrLen = aTextAttrArray.Length();
 
   // Navigate backward from anchor accessible to find start offset.
   for (PRInt32 childIdx = mOffsetAccIdx - 1; childIdx >= 0; childIdx--) {
     nsAccessible *currAcc = mHyperTextAcc->GetChildAt(childIdx);
 
--- a/accessible/src/base/nsTextAttrs.h
+++ b/accessible/src/base/nsTextAttrs.h
@@ -47,17 +47,16 @@ class nsHyperTextAccessible;
 #include "nsIDOMElement.h"
 
 #include "nsIContent.h"
 #include "nsIFrame.h"
 #include "nsIPersistentProperties2.h"
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
-#include "nsTPtrArray.h"
 
 class nsITextAttr;
 
 /**
  * Used to expose text attributes for the hyper text accessible (see
  * nsHyperTextAccessible class). It is indended for the work with 'language' and
  * CSS based text attributes.
  *
@@ -107,17 +106,17 @@ protected:
    * Calculates range (start and end offsets) of text where the text attributes
    * are stretched. New offsets may be smaller if one of text attributes changes
    * its value before or after the given offsets.
    *
    * @param aTextAttrArray  [in] text attributes array
    * @param aStartHTOffset  [in, out] the start offset
    * @param aEndHTOffset    [in, out] the end offset
    */
-   nsresult GetRange(const nsTPtrArray<nsITextAttr>& aTextAttrArray,
+   nsresult GetRange(const nsTArray<nsITextAttr*>& aTextAttrArray,
                      PRInt32 *aStartHTOffset, PRInt32 *aEndHTOffset);
 
 private:
   nsRefPtr<nsHyperTextAccessible> mHyperTextAcc;
 
   PRBool mIncludeDefAttrs;
 
   nsRefPtr<nsAccessible> mOffsetAcc;
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -43,28 +43,27 @@
 
 #include "nsAttrValue.h"
 #include "nsIAtom.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/css/StyleRule.h"
 #include "mozilla/css/Declaration.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDocument.h"
-#include "nsTPtrArray.h"
 #include "nsContentUtils.h"
 #include "nsReadableUtils.h"
 #include "prprf.h"
 #include "nsISVGValue.h"
 
 namespace css = mozilla::css;
 
 #define MISC_STR_PTR(_cont) \
   reinterpret_cast<void*>((_cont)->mStringBits & NS_ATTRVALUE_POINTERVALUE_MASK)
 
-nsTPtrArray<const nsAttrValue::EnumTable>* nsAttrValue::sEnumTableArray = nsnull;
+nsTArray<const nsAttrValue::EnumTable*>* nsAttrValue::sEnumTableArray = nsnull;
 
 nsAttrValue::nsAttrValue()
     : mBits(0)
 {
 }
 
 nsAttrValue::nsAttrValue(const nsAttrValue& aOther)
     : mBits(0)
@@ -102,17 +101,17 @@ nsAttrValue::~nsAttrValue()
 }
 
 /* static */
 nsresult
 nsAttrValue::Init()
 {
   NS_ASSERTION(!sEnumTableArray, "nsAttrValue already initialized");
 
-  sEnumTableArray = new nsTPtrArray<const EnumTable>;
+  sEnumTableArray = new nsTArray<const EnumTable*>;
   NS_ENSURE_TRUE(sEnumTableArray, NS_ERROR_OUT_OF_MEMORY);
   
   return NS_OK;
 }
 
 /* static */
 void
 nsAttrValue::Shutdown()
--- a/content/base/src/nsAttrValue.h
+++ b/content/base/src/nsAttrValue.h
@@ -53,17 +53,16 @@
 #include "nsCOMPtr.h"
 
 typedef PRUptrdiff PtrBits;
 class nsAString;
 class nsIAtom;
 class nsISVGValue;
 class nsIDocument;
 template<class E, class A> class nsTArray;
-template<class E, class A> class nsTPtrArray;
 struct nsTArrayDefaultAllocator;
 
 namespace mozilla {
 namespace css {
 class StyleRule;
 }
 }
 
@@ -372,17 +371,17 @@ private:
   // aStrict is set PR_TRUE if stringifying the return value equals with
   // aValue.
   PRInt32 StringToInteger(const nsAString& aValue,
                           PRBool* aStrict,
                           PRInt32* aErrorCode,
                           PRBool aCanBePercent = PR_FALSE,
                           PRBool* aIsPercent = nsnull) const;
 
-  static nsTPtrArray<const EnumTable, nsTArrayDefaultAllocator>* sEnumTableArray;
+  static nsTArray<const EnumTable*, nsTArrayDefaultAllocator>* sEnumTableArray;
 
   PtrBits mBits;
 };
 
 /**
  * Implementation of inline methods
  */
 
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -129,17 +129,16 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_
 #include "nsXBLBinding.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsEscape.h"
 #include "nsICharsetConverterManager.h"
 #include "nsEventListenerManager.h"
 #include "nsAttrName.h"
 #include "nsIDOMUserDataHandler.h"
 #include "nsContentCreatorFunctions.h"
-#include "nsTPtrArray.h"
 #include "nsGUIEvent.h"
 #include "nsMutationEvent.h"
 #include "nsIMEStateManager.h"
 #include "nsContentErrors.h"
 #include "nsUnicharUtilCIID.h"
 #include "nsCompressedCharMap.h"
 #include "nsINativeKeyBindings.h"
 #include "nsIDOMNSUIEvent.h"
@@ -1553,17 +1552,17 @@ nsINode*
 nsContentUtils::GetCommonAncestor(nsINode* aNode1,
                                   nsINode* aNode2)
 {
   if (aNode1 == aNode2) {
     return aNode1;
   }
 
   // Build the chain of parents
-  nsAutoTPtrArray<nsINode, 30> parents1, parents2;
+  nsAutoTArray<nsINode*, 30> parents1, parents2;
   do {
     parents1.AppendElement(aNode1);
     aNode1 = aNode1->GetNodeParent();
   } while (aNode1);
   do {
     parents2.AppendElement(aNode2);
     aNode2 = aNode2->GetNodeParent();
   } while (aNode2);
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -137,17 +137,16 @@
 #endif /* MOZ_XUL */
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsCCUncollectableMarker.h"
 
 #include "mozAutoDocUpdate.h"
 
 #include "nsCSSParser.h"
-#include "nsTPtrArray.h"
 #include "prprf.h"
 
 #include "nsSVGFeatures.h"
 #include "nsDOMMemoryReporter.h"
 
 using namespace mozilla::dom;
 namespace css = mozilla::css;
 
@@ -751,17 +750,17 @@ PRUint16
 nsINode::CompareDocPosition(nsINode* aOtherNode)
 {
   NS_PRECONDITION(aOtherNode, "don't pass null");
 
   if (this == aOtherNode) {
     return 0;
   }
 
-  nsAutoTPtrArray<nsINode, 32> parents1, parents2;
+  nsAutoTArray<nsINode*, 32> parents1, parents2;
 
   nsINode *node1 = aOtherNode, *node2 = this;
 
   // Check if either node is an attribute
   nsIAttribute* attr1 = nsnull;
   if (node1->IsNodeOfType(nsINode::eATTRIBUTE)) {
     attr1 = static_cast<nsIAttribute*>(node1);
     nsIContent* elem = attr1->GetContent();
--- a/content/html/content/src/nsHTMLFieldSetElement.h
+++ b/content/html/content/src/nsHTMLFieldSetElement.h
@@ -36,17 +36,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsHTMLFieldSetElement_h___
 #define nsHTMLFieldSetElement_h___
 
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMHTMLFieldSetElement.h"
 #include "nsIConstraintValidation.h"
-#include "nsTPtrArray.h"
 
 
 class nsHTMLFieldSetElement : public nsGenericHTMLFormElement,
                               public nsIDOMHTMLFieldSetElement,
                               public nsIConstraintValidation
 {
 public:
   using nsIConstraintValidation::GetValidationMessage;
@@ -108,15 +107,15 @@ private:
   // This function is used to generate the nsContentList (listed form elements).
   static PRBool MatchListedElements(nsIContent* aContent, PRInt32 aNamespaceID,
                                     nsIAtom* aAtom, void* aData);
 
   // listed form controls elements.
   nsRefPtr<nsContentList> mElements;
 
   // List of elements which have this fieldset as first fieldset ancestor.
-  nsTPtrArray<nsGenericHTMLFormElement> mDependentElements;
+  nsTArray<nsGenericHTMLFormElement*> mDependentElements;
 
   nsIContent* mFirstLegend;
 };
 
 #endif /* nsHTMLFieldSetElement_h___ */
 
--- a/content/xslt/src/base/txOwningArray.h
+++ b/content/xslt/src/base/txOwningArray.h
@@ -34,27 +34,25 @@
  * 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 txOwningArray_h__
 #define txOwningArray_h__
 
-#include "nsTPtrArray.h"
-
-// Class acting like a nsTPtrArray except that it deletes its objects
+// Class acting like a nsTArray except that it deletes its objects
 // on destruction. It does not however delete its objects on operations
 // like RemoveElementsAt or on |array[i] = bar|.
 
 template<class E>
-class txOwningArray : public nsTPtrArray<E>
+class txOwningArray : public nsTArray<E*>
 {
 public:
-    typedef nsTPtrArray<E> base_type;
+    typedef nsTArray<E*> base_type;
     typedef typename base_type::elem_type elem_type;
 
     ~txOwningArray()
     {
         elem_type* iter = base_type::Elements();
         elem_type* end = iter + base_type::Length();
         for (; iter < end; ++iter) {
             delete *iter;
--- a/content/xslt/src/xslt/txStylesheet.cpp
+++ b/content/xslt/src/xslt/txStylesheet.cpp
@@ -312,17 +312,17 @@ txStylesheet::doneCompiling()
     rv = addFrames(frameIter);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Loop through importframes in decreasing-precedence-order and process
     // all items
     frameIter.reset();
     ImportFrame* frame;
     while ((frame = static_cast<ImportFrame*>(frameIter.next()))) {
-        nsTPtrArray<txStripSpaceTest> frameStripSpaceTests;
+        nsTArray<txStripSpaceTest*> frameStripSpaceTests;
 
         txListIterator itemIter(&frame->mToplevelItems);
         itemIter.resetToEnd();
         txToplevelItem* item;
         while ((item = static_cast<txToplevelItem*>(itemIter.previous()))) {
             switch (item->getType()) {
                 case txToplevelItem::attributeSet:
                 {
@@ -497,17 +497,17 @@ txStylesheet::addFrames(txListIterator& 
         }
     }
     
     return NS_OK;
 }
 
 nsresult
 txStylesheet::addStripSpace(txStripSpaceItem* aStripSpaceItem,
-                            nsTPtrArray<txStripSpaceTest>& aFrameStripSpaceTests)
+                            nsTArray<txStripSpaceTest*>& aFrameStripSpaceTests)
 {
     PRInt32 testCount = aStripSpaceItem->mStripSpaceTests.Length();
     for (; testCount > 0; --testCount) {
         txStripSpaceTest* sst = aStripSpaceItem->mStripSpaceTests[testCount-1];
         double priority = sst->getDefaultPriority();
         PRInt32 i, frameCount = aFrameStripSpaceTests.Length();
         for (i = 0; i < frameCount; ++i) {
             if (aFrameStripSpaceTests[i]->getDefaultPriority() < priority) {
--- a/content/xslt/src/xslt/txStylesheet.h
+++ b/content/xslt/src/xslt/txStylesheet.h
@@ -38,17 +38,16 @@
 
 #ifndef TX_TXSTYLESHEET_H
 #define TX_TXSTYLESHEET_H
 
 #include "txOutputFormat.h"
 #include "txExpandedNameMap.h"
 #include "txList.h"
 #include "txXSLTPatterns.h"
-#include "nsTPtrArray.h"
 #include "nsISupportsImpl.h"
 
 class txInstruction;
 class txToplevelItem;
 class txTemplateItem;
 class txVariableItem;
 class txStripSpaceItem;
 class txAttributeSetItem;
@@ -140,17 +139,17 @@ public:
         PRBool mIsParam;
     };
 
 private:
     nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame);
     nsresult addGlobalVariable(txVariableItem* aVariable);
     nsresult addFrames(txListIterator& aInsertIter);
     nsresult addStripSpace(txStripSpaceItem* aStripSpaceItem,
-                           nsTPtrArray<txStripSpaceTest>& aFrameStripSpaceTests);
+                           nsTArray<txStripSpaceTest*>& aFrameStripSpaceTests);
     nsresult addAttributeSet(txAttributeSetItem* aAttributeSetItem);
 
     // List of ImportFrames
     txList mImportFrames;
     
     // output format
     txOutputFormat mOutputFormat;
 
--- a/content/xslt/src/xslt/txToplevelItems.h
+++ b/content/xslt/src/xslt/txToplevelItems.h
@@ -128,17 +128,17 @@ class txStripSpaceItem : public txToplev
 {
 public:
     ~txStripSpaceItem();
 
     TX_DECL_TOPLEVELITEM
 
     nsresult addStripSpaceTest(txStripSpaceTest* aStripSpaceTest);
 
-    nsTPtrArray<txStripSpaceTest> mStripSpaceTests;
+    nsTArray<txStripSpaceTest*> mStripSpaceTests;
 };
 
 // xsl:template
 class txTemplateItem : public txInstructionContainer
 {
 public:
     txTemplateItem(nsAutoPtr<txPattern> aMatch, const txExpandedName& aName,
                    const txExpandedName& aMode, double aPrio);
--- a/content/xul/document/src/nsXULControllers.h
+++ b/content/xul/document/src/nsXULControllers.h
@@ -41,17 +41,16 @@
   The XUL "controllers" object.
 
 */
 
 #ifndef nsXULControllers_h__
 #define nsXULControllers_h__
 
 #include "nsCOMPtr.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 +91,16 @@ public:
     NS_DECL_NSISECURITYCHECKEDCOMPONENT
   
 protected:
     nsXULControllers();
     virtual ~nsXULControllers(void);
 
     void        DeleteControllers();
 
-    nsTPtrArray<nsXULControllerData> mControllers;
+    nsTArray<nsXULControllerData*>   mControllers;
     PRUint32                         mCurControllerID;
 };
 
 
 
 
 #endif // nsXULControllers_h__
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -37,17 +37,16 @@
 #include "mozilla/dom/TabParent.h"
 
 #include "nsFocusManager.h"
 
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIServiceManager.h"
 #include "nsIEnumerator.h"
-#include "nsTPtrArray.h"
 #include "nsGkAtoms.h"
 #include "nsContentUtils.h"
 #include "nsIDocument.h"
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMNSHTMLFrameElement.h"
@@ -1293,17 +1292,17 @@ nsFocusManager::GetCommonAncestor(nsPIDO
   nsCOMPtr<nsIWebNavigation> webnav(do_GetInterface(aWindow1));
   nsCOMPtr<nsIDocShellTreeItem> dsti1 = do_QueryInterface(webnav);
   NS_ENSURE_TRUE(dsti1, nsnull);
 
   webnav = do_GetInterface(aWindow2);
   nsCOMPtr<nsIDocShellTreeItem> dsti2 = do_QueryInterface(webnav);
   NS_ENSURE_TRUE(dsti2, nsnull);
 
-  nsAutoTPtrArray<nsIDocShellTreeItem, 30> parents1, parents2;
+  nsAutoTArray<nsIDocShellTreeItem*, 30> parents1, parents2;
   do {
     parents1.AppendElement(dsti1);
     nsCOMPtr<nsIDocShellTreeItem> parentDsti1;
     dsti1->GetParent(getter_AddRefs(parentDsti1));
     dsti1.swap(parentDsti1);
   } while (dsti1);
   do {
     parents2.AppendElement(dsti2);
--- a/dom/system/nsDeviceMotion.cpp
+++ b/dom/system/nsDeviceMotion.cpp
@@ -44,18 +44,18 @@
 #include "nsIServiceManager.h"
 #include "nsIPrivateDOMEvent.h"
 #include "nsIDOMDeviceOrientationEvent.h"
 #include "nsIDOMDeviceMotionEvent.h"
 #include "nsIServiceManager.h"
 #include "nsIPrefService.h"
 #include "nsDOMDeviceMotionEvent.h"
 
-static const nsTPtrArray<nsIDOMWindow>::index_type NoIndex =
-    nsTPtrArray<nsIDOMWindow>::NoIndex;
+static const nsTArray<nsIDOMWindow*>::index_type NoIndex =
+    nsTArray<nsIDOMWindow*>::NoIndex;
 
 class nsDeviceMotionData : public nsIDeviceMotionData
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDEVICEMOTIONDATA
 
   nsDeviceMotionData(unsigned long type, double x, double y, double z);
--- a/dom/system/nsDeviceMotion.h
+++ b/dom/system/nsDeviceMotion.h
@@ -35,17 +35,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsDeviceMotion_h
 #define nsDeviceMotion_h
 
 #include "nsIDeviceMotion.h"
 #include "nsIDOMDeviceMotionEvent.h"
 #include "nsCOMArray.h"
-#include "nsTPtrArray.h"
 #include "nsCOMPtr.h"
 #include "nsITimer.h"
 
 #define NS_DEVICE_MOTION_CID \
 { 0xecba5203, 0x77da, 0x465a, \
 { 0x86, 0x5e, 0x78, 0xb7, 0xaf, 0x10, 0xd8, 0xf7 } }
 
 #define NS_DEVICE_MOTION_CONTRACTID "@mozilla.org/devicemotion;1"
@@ -60,17 +59,17 @@ public:
   NS_DECL_NSIDEVICEMOTIONUPDATE
 
   nsDeviceMotion();
 
   virtual ~nsDeviceMotion();
 
 private:
   nsCOMArray<nsIDeviceMotionListener> mListeners;
-  nsTPtrArray<nsIDOMWindow> mWindowListeners;
+  nsTArray<nsIDOMWindow*> mWindowListeners;
 
   void StartDisconnectTimer();
 
   PRBool mStarted;
 
   nsCOMPtr<nsITimer> mTimeoutTimer;
   static void TimeoutHandler(nsITimer *aTimer, void *aClosure);
 
--- a/layout/tables/nsCellMap.cpp
+++ b/layout/tables/nsCellMap.cpp
@@ -263,17 +263,17 @@ nsTableCellMap::GetMapFor(const nsTableR
 
   return nsnull;
 }
 
 void
 nsTableCellMap::Synchronize(nsTableFrame* aTableFrame)
 {
   nsTableFrame::RowGroupArray orderedRowGroups;
-  nsAutoTPtrArray<nsCellMap, 8> maps;
+  nsAutoTArray<nsCellMap*, 8> maps;
 
   aTableFrame->OrderRowGroups(orderedRowGroups);
   if (!orderedRowGroups.Length()) {
     return;
   }
 
   // XXXbz this fails if orderedRowGroups is missing some row groups
   // (due to OOM when appending to the array, e.g. -- we leak maps in
--- a/layout/tables/nsCellMap.h
+++ b/layout/tables/nsCellMap.h
@@ -35,17 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsCellMap_h__
 #define nsCellMap_h__
 
 #include "nscore.h"
 #include "celldata.h"
 #include "nsTArray.h"
-#include "nsTPtrArray.h"
+#include "nsTArray.h"
 #include "nsRect.h"
 #include "nsCOMPtr.h"
 #include "nsAlgorithm.h"
 #include "nsAutoPtr.h"
 
 #undef DEBUG_TABLE_CELLMAP
 
 class nsTableColFrame;
@@ -455,17 +455,17 @@ public:
                      PRInt32 aColIndex,
                      PRBool  aGetEffective) const;
 
   PRInt32 GetEffectiveColSpan(const nsTableCellMap& aMap,
                               PRInt32     aRowIndex,
                               PRInt32     aColIndex,
                               PRBool&     aIsZeroColSpan) const;
 
-  typedef nsTPtrArray<CellData> CellDataArray;
+  typedef nsTArray<CellData*> CellDataArray;
 
   /** dump a representation of the cell map to stdout for debugging */
 #ifdef NS_DEBUG
   void Dump(PRBool aIsBorderCollapse) const;
 #endif
 
 protected:
   friend class nsTableCellMap;
--- a/layout/tables/nsTableFrame.h
+++ b/layout/tables/nsTableFrame.h
@@ -33,17 +33,16 @@
  * 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 nsTableFrame_h__
 #define nsTableFrame_h__
 
 #include "nscore.h"
-#include "nsTPtrArray.h"
 #include "nsHTMLContainerFrame.h"
 #include "nsStyleCoord.h"
 #include "nsStyleConsts.h"
 #include "nsITableLayout.h"
 #include "nsTableColFrame.h"
 #include "nsTableColGroupFrame.h"
 #include "nsCellMap.h"
 #include "nsGkAtoms.h"
@@ -610,17 +609,17 @@ protected:
                   const nsRect&        aOriginalKidRect,
                   const nsRect&        aOriginalKidVisualOverflow);
    void PlaceRepeatedFooter(nsTableReflowState& aReflowState,
                             nsTableRowGroupFrame *aTfoot,
                             nscoord aFooterHeight);
 
   nsIFrame* GetFirstBodyRowGroupFrame();
 public:
-  typedef nsAutoTPtrArray<nsTableRowGroupFrame, 8> RowGroupArray;
+  typedef nsAutoTArray<nsTableRowGroupFrame*, 8> RowGroupArray;
   /**
    * Push all our child frames from the aRowGroups array, in order, starting
    * from the frame at aPushFrom to the end of the array. The frames are put on
    * our overflow list or moved directly to our next-in-flow if one exists.
    */
 protected:
   void PushChildren(const RowGroupArray& aRowGroups, PRInt32 aPushFrom);
 
@@ -771,17 +770,17 @@ public:
             PRBool          aDumpCellMap);
 #endif
 
 protected:
 #ifdef DEBUG
   void DumpRowGroup(nsIFrame* aChildFrame);
 #endif
   // DATA MEMBERS
-  nsAutoTPtrArray<nsTableColFrame, 8> mColFrames;
+  nsAutoTArray<nsTableColFrame*, 8> mColFrames;
 
   struct TableBits {
     PRUint32 mHaveReflowedColGroups:1; // have the col groups gotten their initial reflow
     PRUint32 mHasPctCol:1;             // does any cell or col have a pct width
     PRUint32 mCellSpansPctCol:1;       // does any cell span a col with a pct width (or containing a cell with a pct width)
     PRUint32 mIsBorderCollapse:1;      // border collapsing model vs. separate model
     PRUint32 mRowInserted:1;
     PRUint32 mNeedToCalcBCBorders:1;
--- a/widget/src/windows/nsDataObj.h
+++ b/widget/src/windows/nsDataObj.h
@@ -46,17 +46,16 @@
 #include <oleidl.h>
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsILocalFile.h"
 #include "nsIURI.h"
 #include "nsIInputStream.h"
 #include "nsIChannel.h"
-#include "nsTPtrArray.h"
 #include "nsCOMArray.h"
 #include "nsITimer.h"
 
 // XXX for older version of PSDK where IAsyncOperation and related stuff is not available
 // but thisdefine  should be removed when parocles config is updated
 #ifndef __IAsyncOperation_INTERFACE_DEFINED__
 // IAsyncOperation interface definition
 EXTERN_C const IID IID_IAsyncOperation;
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -139,17 +139,16 @@
 #include "prtime.h"
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include "mozilla/FunctionTimer.h"
 #include "nsIObserverService.h"
 #include "nsIConsoleService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
-#include "nsTPtrArray.h"
 #include "nsTArray.h"
 #include "mozilla/Services.h"
 #include "nsICycleCollectorListener.h"
 #include "nsIXPConnect.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIMemoryReporter.h"
 #include "xpcpublic.h"
 #include <stdio.h>
@@ -1053,17 +1052,17 @@ struct nsCycleCollector
 
     nsCycleCollectionLanguageRuntime *mRuntimes[nsIProgrammingLanguage::MAX+1];
     nsCycleCollectionXPCOMRuntime mXPCOMRuntime;
 
     GCGraph mGraph;
 
     nsCycleCollectorParams mParams;
 
-    nsTPtrArray<PtrInfo> *mWhiteNodes;
+    nsTArray<PtrInfo*> *mWhiteNodes;
     PRUint32 mWhiteNodeCount;
 
     // mVisitedRefCounted and mVisitedGCed are only used for telemetry
     PRUint32 mVisitedRefCounted;
     PRUint32 mVisitedGCed;
 
     nsPurpleBuffer mPurpleBuf;
 
@@ -1086,17 +1085,17 @@ struct nsCycleCollector
     PRBool Forget(nsISupports *n);
     nsPurpleBufferEntry* Suspect2(nsISupports *n);
     PRBool Forget2(nsPurpleBufferEntry *e);
 
     PRUint32 Collect(PRUint32 aTryCollections,
                      nsICycleCollectorListener *aListener);
 
     // Prepare for and cleanup after one or more collection(s).
-    PRBool PrepareForCollection(nsTPtrArray<PtrInfo> *aWhiteNodes);
+    PRBool PrepareForCollection(nsTArray<PtrInfo*> *aWhiteNodes);
     void GCIfNeeded(PRBool aForceGC);
     void CleanupAfterCollection();
 
     // Start and finish an individual collection.
     PRBool BeginCollection(nsICycleCollectorListener *aListener);
     PRBool FinishCollection();
 
     PRUint32 SuspectedCount();
@@ -2596,17 +2595,17 @@ nsCycleCollector::GCIfNeeded(PRBool aFor
     // which returns false if not in the main thread.
     rt->Collect();
 #ifdef COLLECT_TIME_DEBUG
     printf("cc: GC() took %lldms\n", (PR_Now() - start) / PR_USEC_PER_MSEC);
 #endif
 }
 
 PRBool
-nsCycleCollector::PrepareForCollection(nsTPtrArray<PtrInfo> *aWhiteNodes)
+nsCycleCollector::PrepareForCollection(nsTArray<PtrInfo*> *aWhiteNodes)
 {
 #if defined(DEBUG_CC) && !defined(__MINGW32__)
     if (!mParams.mDoNothing && mParams.mHookMalloc)
         InitMemHook();
 #endif
 
     // This can legitimately happen in a few cases. See bug 383651.
     if (mCollectionInProgress)
@@ -2662,17 +2661,17 @@ nsCycleCollector::CleanupAfterCollection
     ExplainLiveExpectedGarbage();
 #endif
 }
 
 PRUint32
 nsCycleCollector::Collect(PRUint32 aTryCollections,
                           nsICycleCollectorListener *aListener)
 {
-    nsAutoTPtrArray<PtrInfo, 4000> whiteNodes;
+    nsAutoTArray<PtrInfo*, 4000> whiteNodes;
 
     if (!PrepareForCollection(&whiteNodes))
         return 0;
 
     PRUint32 totalCollections = 0;
     while (aTryCollections > totalCollections) {
         // Synchronous cycle collection. Always force a JS GC beforehand.
         GCIfNeeded(PR_TRUE);
@@ -3506,17 +3505,17 @@ public:
 
         mCollector->GCIfNeeded(PR_FALSE);
 
         MutexAutoLock autoLock(mLock);
 
         if (!mRunning)
             return 0;
 
-        nsAutoTPtrArray<PtrInfo, 4000> whiteNodes;
+        nsAutoTArray<PtrInfo*, 4000> whiteNodes;
         if (!mCollector->PrepareForCollection(&whiteNodes))
             return 0;
 
         NS_ASSERTION(!mListener, "Should have cleared this already!");
         mListener = aListener;
 
         mRequest.Notify();
         mReply.Wait();
--- a/xpcom/build/XPCOM.h
+++ b/xpcom/build/XPCOM.h
@@ -20,17 +20,16 @@
 #include "nsMemory.h"
 #include "nsTraceRefcnt.h"
 
 #include "nsID.h"
 
 #include "nsISupports.h"
 
 #include "nsTArray.h"
-#include "nsTPtrArray.h"
 #include "nsTWeakRef.h"
 
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 
 #ifndef MOZILLA_INTERNAL_API
 #include "nsStringAPI.h"
 #else
--- a/xpcom/glue/Makefile.in
+++ b/xpcom/glue/Makefile.in
@@ -92,17 +92,16 @@ SDK_HEADERS = \
 		nsRefPtrHashtable.h \
 		nsServiceManagerUtils.h \
 		nsStringAPI.h \
 		nsStringGlue.h \
 		nsTArray.h \
 		nsTArray-inl.h \
 		nsTHashtable.h \
 		nsTObserverArray.h \
-		nsTPtrArray.h \
 		nsTWeakRef.h \
 		nsTextFormatter.h \
 		nsTraceRefcnt.h \
 		nsVersionComparator.h \
 		nsVoidArray.h \
 		nsWeakReference.h \
 		pldhash.h \
 		$(NULL)
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -108,16 +108,46 @@ struct NS_COM_GLUE nsTArrayHeader
 {
   static nsTArrayHeader sEmptyHdr;
 
   PRUint32 mLength;
   PRUint32 mCapacity : 31;
   PRUint32 mIsAutoArray : 1;
 };
 
+// This class provides a SafeElementAt method to nsTArray<T*> which does
+// not take a second default value parameter.
+template <class E, class Derived>
+struct nsTArray_SafeElementAtHelper
+{
+  typedef E*       elem_type;
+  typedef PRUint32 index_type;
+
+  // No implementation is provided for these two methods, and that is on
+  // purpose, since we don't support these functions on non-pointer type
+  // instantiations.
+  elem_type& SafeElementAt(index_type i);
+  const elem_type& SafeElementAt(index_type i) const;
+};
+
+template <class E, class Derived>
+struct nsTArray_SafeElementAtHelper<E*, Derived>
+{
+  typedef E*       elem_type;
+  typedef PRUint32 index_type;
+
+  elem_type SafeElementAt(index_type i) {
+    return static_cast<Derived*> (this)->SafeElementAt(i, nsnull);
+  }
+
+  const elem_type SafeElementAt(index_type i) const {
+    return static_cast<const Derived*> (this)->SafeElementAt(i, nsnull);
+  }
+};
+
 
 //
 // This class serves as a base class for nsTArray.  It shouldn't be used
 // directly.  It holds common implementation code that does not depend on the
 // element type of the nsTArray.
 //
 template<class Alloc>
 class nsTArray_base
@@ -344,25 +374,29 @@ public:
 // "fallible" and "infallible" nsTArray (if available), defaulting to
 // fallible.  If the *fallible* allocator is used, the return value of
 // methods that might allocate needs to be checked; Append() is
 // one such method.  These return values don't need to be checked if
 // the *in*fallible allocator is chosen.  When in doubt, choose the
 // infallible allocator.
 //
 template<class E, class Alloc=nsTArrayDefaultAllocator>
-class nsTArray : public nsTArray_base<Alloc>
+class nsTArray : public nsTArray_base<Alloc>,
+                 public nsTArray_SafeElementAtHelper<E, nsTArray<E, Alloc> >
 {
 public:
   typedef nsTArray_base<Alloc>           base_type;
   typedef typename base_type::size_type  size_type;
   typedef typename base_type::index_type index_type;
   typedef E                              elem_type;
   typedef nsTArray<E, Alloc>             self_type;
   typedef nsTArrayElementTraits<E>       elem_traits;
+  typedef nsTArray_SafeElementAtHelper<E, self_type> safeelementat_helper_type;
+
+  using safeelementat_helper_type::SafeElementAt;
 
   // A special value that is used to indicate an invalid or unknown index
   // into the array.
   enum {
     NoIndex = index_type(-1)
   };
 
   using base_type::Length;
deleted file mode 100644
--- a/xpcom/glue/nsTPtrArray.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is C++ pointer array template.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *  Jonas Sicking <jonas@sicking.cc>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-
-#ifndef nsTPtrArray_h__
-#define nsTPtrArray_h__
-
-#include "nsTArray.h"
-
-//
-// The templatized array class for storing pointers. The class is based on
-// nsTArray and has all the features of that class, in addition to an
-// implementation of SafeElementAt that returns null for out of bounds access
-//
-template<class E, class Alloc=nsTArrayDefaultAllocator>
-class nsTPtrArray : public nsTArray<E*, Alloc> {
-  public:
-  typedef nsTPtrArray<E, Alloc> self_type;
-  typedef nsTArray<E*, Alloc> base_type;
-    typedef typename base_type::size_type size_type;
-    typedef typename base_type::elem_type elem_type;
-    typedef typename base_type::index_type index_type;
-
-    //
-    // Initialization methods
-    //
-
-    nsTPtrArray() {}
-
-    // Initialize this array and pre-allocate some number of elements.
-    explicit nsTPtrArray(size_type capacity) {
-      this->SetCapacity(capacity);
-    }
-    
-    // The array's copy-constructor performs a 'deep' copy of the given array.
-    // @param other  The array object to copy.
-    nsTPtrArray(const self_type& other) {
-      this->AppendElements(other);
-    }
-
-    //
-    // Accessor methods
-    //
-
-    // Forward SafeElementAt to avoid shadowing (and warnings thereof)
-    elem_type& SafeElementAt(index_type i, elem_type& def) {
-      return base_type::SafeElementAt(i, def);
-    }
-    const elem_type& SafeElementAt(index_type i, const elem_type& def) const {
-      return base_type::SafeElementAt(i, def);
-    }
-
-    // This method provides direct access to the i'th element of the array in
-    // a bounds safe manner. If the requested index is out of bounds null is
-    // returned.
-    // @param i  The index of an element in the array.
-    elem_type SafeElementAt(index_type i) const {
-      return SafeElementAt(i, nsnull);
-    }
-};
-
-template<class E, PRUint32 N, class Alloc=nsTArrayDefaultAllocator>
-class nsAutoTPtrArray : public nsTPtrArray<E, Alloc> {
-  public:
-    typedef nsTPtrArray<E, Alloc> base_type;
-    typedef typename base_type::Header Header;
-    typedef typename base_type::elem_type elem_type;
-
-    nsAutoTPtrArray() {
-      *base_type::PtrToHdr() = reinterpret_cast<Header*>(&mAutoBuf);
-      base_type::Hdr()->mLength = 0;
-      base_type::Hdr()->mCapacity = N;
-      base_type::Hdr()->mIsAutoArray = 1;
-
-      NS_ASSERTION(base_type::GetAutoArrayBuffer() ==
-                   reinterpret_cast<Header*>(&mAutoBuf),
-                   "GetAutoArrayBuffer needs to be fixed");
-    }
-
-  protected:
-    union {
-      char mAutoBuf[sizeof(Header) + N * sizeof(elem_type)];
-      PRUint64 dummy;
-    };
-};
-
-#endif  // nsTPtrArray_h__
--- a/xpcom/tests/TestTArray.cpp
+++ b/xpcom/tests/TestTArray.cpp
@@ -34,17 +34,16 @@
  * 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 ***** */
 
 #include <stdlib.h>
 #include <stdio.h>
 #include "nsTArray.h"
-#include "nsTPtrArray.h"
 #include "nsMemory.h"
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsXPCOM.h"
 #include "nsILocalFile.h"
@@ -423,29 +422,29 @@ static PRBool test_refptr_array() {
   b->Release();
   c->Release();
   return rv;
 }
 
 //----
 
 static PRBool test_ptrarray() {
-  nsTPtrArray<PRUint32> ary;
+  nsTArray<PRUint32*> ary;
   if (ary.SafeElementAt(0) != nsnull)
     return PR_FALSE;
   if (ary.SafeElementAt(1000) != nsnull)
     return PR_FALSE;
   PRUint32 a = 10;
   ary.AppendElement(&a);
   if (*ary[0] != a)
     return PR_FALSE;
   if (*ary.SafeElementAt(0) != a)
     return PR_FALSE;
 
-  nsTPtrArray<const PRUint32> cary;
+  nsTArray<const PRUint32*> cary;
   if (cary.SafeElementAt(0) != nsnull)
     return PR_FALSE;
   if (cary.SafeElementAt(1000) != nsnull)
     return PR_FALSE;
   const PRUint32 b = 14;
   cary.AppendElement(&a);
   cary.AppendElement(&b);
   if (*cary[0] != a || *cary[1] != b)