Bug 1312144 - Part 1: Stop using nsISupportsArray in nsDirectoryViewer. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Mon, 24 Oct 2016 11:31:15 -0700
changeset 319196 3eb7745dd704c2596eea71a2da5a08695828e012
parent 319195 70280cfa7c118cf4bd686b55ece44534d3128d5b
child 319197 7666e62d299dda5738c00420284af78ed81c90ff
push id83094
push usererahm@mozilla.com
push dateMon, 24 Oct 2016 18:31:20 +0000
treeherdermozilla-inbound@3eb7745dd704 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1312144
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1312144 - Part 1: Stop using nsISupportsArray in nsDirectoryViewer. r=froydnj This swaps out nsIMutableArray for nsISupportsArray. MozReview-Commit-ID: 9iZynpMcq6A
xpfe/components/directory/nsDirectoryViewer.cpp
xpfe/components/directory/nsDirectoryViewer.h
--- a/xpfe/components/directory/nsDirectoryViewer.cpp
+++ b/xpfe/components/directory/nsDirectoryViewer.cpp
@@ -11,27 +11,28 @@
   http://www.mozilla.org/projects/netlib/dirindexformat.html
 
   One added change is for a description entry, for when the
   target does not match the filename
 
 */
 
 #include "nsDirectoryViewer.h"
+#include "nsArray.h"
+#include "nsArrayUtils.h"
 #include "nsIDirIndex.h"
 #include "nsIDocShell.h"
 #include "jsapi.h"
 #include "nsCOMPtr.h"
 #include "nsEnumeratorUtils.h"
 #include "nsEscape.h"
 #include "nsIRDFService.h"
 #include "nsRDFCID.h"
 #include "rdf.h"
 #include "nsIServiceManager.h"
-#include "nsISupportsArray.h"
 #include "nsIXPConnect.h"
 #include "nsEnumeratorUtils.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsITextToSubURI.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
@@ -585,18 +586,17 @@ nsHTTPIndex::CommonInit()
     mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IsContainer"),
                          getter_AddRefs(kNC_IsContainer));
 
     rv = mDirRDF->GetLiteral(u"true", getter_AddRefs(kTrueLiteral));
     if (NS_FAILED(rv)) return(rv);
     rv = mDirRDF->GetLiteral(u"false", getter_AddRefs(kFalseLiteral));
     if (NS_FAILED(rv)) return(rv);
 
-    rv = NS_NewISupportsArray(getter_AddRefs(mConnectionList));
-    if (NS_FAILED(rv)) return(rv);
+    mConnectionList = nsArray::Create();
 
     // note: don't register DS here
     return rv;
 }
 
 
 nsresult
 nsHTTPIndex::Init()
@@ -843,21 +843,22 @@ nsHTTPIndex::GetTargets(nsIRDFResource *
 			  doNetworkRequest = false;
 		}
 
         // Note: if we need to do a network request, do it out-of-band
         // (because the XUL template builder isn't re-entrant)
         // by using a global connection list and an immediately-firing timer
 		if (doNetworkRequest && mConnectionList)
 		{
-		    int32_t connectionIndex = mConnectionList->IndexOf(aSource);
-		    if (connectionIndex < 0)
+		    uint32_t connectionIndex;
+                    nsresult idx_rv = mConnectionList->IndexOf(0, aSource, &connectionIndex);
+		    if (NS_FAILED(idx_rv))
 		    {
     		    // add aSource into list of connections to make
-	    	    mConnectionList->AppendElement(aSource);
+	    	    mConnectionList->AppendElement(aSource, /*weak =*/ false);
 
                 // if we don't have a timer about to fire, create one
                 // which should fire as soon as possible (out-of-band)
             	if (!mTimer)
             	{
             		mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
             		NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a timer");
             		if (NS_SUCCEEDED(rv))
@@ -878,24 +879,23 @@ nsHTTPIndex::GetTargets(nsIRDFResource *
 
 nsresult
 nsHTTPIndex::AddElement(nsIRDFResource *parent, nsIRDFResource *prop, nsIRDFNode *child)
 {
     nsresult    rv;
 
     if (!mNodeList)
     {
-        rv = NS_NewISupportsArray(getter_AddRefs(mNodeList));
-        if (NS_FAILED(rv)) return(rv);
+        mNodeList = nsArray::Create();
     }
 
     // order required: parent, prop, then child
-    mNodeList->AppendElement(parent);
-    mNodeList->AppendElement(prop);
-    mNodeList->AppendElement(child);
+    mNodeList->AppendElement(parent, /*weak =*/ false);
+    mNodeList->AppendElement(prop, /*weak =*/ false);
+    mNodeList->AppendElement(child, /*weak = */ false);
 
 	if (!mTimer)
 	{
 		mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
 		NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a timer");
 		if (NS_FAILED(rv))  return(rv);
 
 		mTimer->InitWithFuncCallback(nsHTTPIndex::FireTimer, this, 1,
@@ -913,30 +913,26 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer,
   nsHTTPIndex *httpIndex = static_cast<nsHTTPIndex *>(aClosure);
   if (!httpIndex)
     return;
 
   // don't return out of this loop as mTimer may need to be cancelled afterwards
   uint32_t numItems = 0;
   if (httpIndex->mConnectionList)
   {
-    httpIndex->mConnectionList->Count(&numItems);
+    httpIndex->mConnectionList->GetLength(&numItems);
     if (numItems > 0)
     {
-      nsCOMPtr<nsISupports> isupports;
-      httpIndex->mConnectionList->GetElementAt((uint32_t)0, getter_AddRefs(isupports));
-      httpIndex->mConnectionList->RemoveElementAt((uint32_t)0);
-
-      nsCOMPtr<nsIRDFResource> source;
-      if (isupports)
-        aSource = do_QueryInterface(isupports);
+      nsCOMPtr<nsIRDFResource> source =
+          do_QueryElementAt(httpIndex->mConnectionList, 0);
+      httpIndex->mConnectionList->RemoveElementAt(0);
 
       nsXPIDLCString uri;
-      if (aSource) {
-        httpIndex->GetDestination(aSource, uri);
+      if (source) {
+        httpIndex->GetDestination(source, uri);
       }
 
       if (!uri) {
         NS_ERROR("Could not reconstruct uri");
         return;
       }
 
       nsresult rv = NS_OK;
@@ -955,44 +951,35 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer,
         channel->SetNotificationCallbacks(httpIndex);
         rv = channel->AsyncOpen2(httpIndex);
       }
     }
   }
 
   if (httpIndex->mNodeList)
   {
-    httpIndex->mNodeList->Count(&numItems);
+    httpIndex->mNodeList->GetLength(&numItems);
     if (numItems > 0)
     {
       // account for order required: src, prop, then target
       numItems /=3;
       if (numItems > 10)
         numItems = 10;
 
       int32_t loop;
       for (loop=0; loop<(int32_t)numItems; loop++)
       {
-        nsCOMPtr<nsISupports> isupports;
-        httpIndex->mNodeList->GetElementAt((uint32_t)0, getter_AddRefs(isupports));
-        httpIndex->mNodeList->RemoveElementAt((uint32_t)0);
-        nsCOMPtr<nsIRDFResource> src;
-        if (isupports)
-          src = do_QueryInterface(isupports);
-        httpIndex->mNodeList->GetElementAt((uint32_t)0, getter_AddRefs(isupports));
-        httpIndex->mNodeList->RemoveElementAt((uint32_t)0);
-        nsCOMPtr<nsIRDFResource> prop;
-        if (isupports)
-          prop = do_QueryInterface(isupports);
+        nsCOMPtr<nsIRDFResource> src = do_QueryElementAt(httpIndex->mNodeList, 0);
+        httpIndex->mNodeList->RemoveElementAt(0);
 
-        httpIndex->mNodeList->GetElementAt((uint32_t)0, getter_AddRefs(isupports));
-        httpIndex->mNodeList->RemoveElementAt((uint32_t)0);
-        nsCOMPtr<nsIRDFNode> target;
-        if (isupports)
-          target = do_QueryInterface(isupports);
+        nsCOMPtr<nsIRDFResource> prop = do_QueryElementAt(httpIndex->mNodeList, 0);
+        httpIndex->mNodeList->RemoveElementAt(0);
+
+        nsCOMPtr<nsIRDFNode> target = do_QueryElementAt(httpIndex->mNodeList, 0);
+        httpIndex->mNodeList->RemoveElementAt(0);
 
         if (src && prop && target)
         {
           if (prop.get() == httpIndex->kNC_Loading)
           {
             httpIndex->Unassert(src, prop, target);
           }
           else
@@ -1003,29 +990,30 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer,
       }
     }
   }
 
   bool refireTimer = false;
   // check both lists to see if the timer needs to continue firing
   if (httpIndex->mConnectionList)
   {
-    httpIndex->mConnectionList->Count(&numItems);
+    httpIndex->mConnectionList->GetLength(&numItems);
     if (numItems > 0)
     {
       refireTimer = true;
     }
     else
     {
       httpIndex->mConnectionList->Clear();
     }
   }
+
   if (httpIndex->mNodeList)
   {
-    httpIndex->mNodeList->Count(&numItems);
+    httpIndex->mNodeList->GetLength(&numItems);
     if (numItems > 0)
     {
       refireTimer = true;
     }
     else
     {
       httpIndex->mNodeList->Clear();
     }
--- a/xpfe/components/directory/nsDirectoryViewer.h
+++ b/xpfe/components/directory/nsDirectoryViewer.h
@@ -1,32 +1,34 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsdirectoryviewer__h____
 #define nsdirectoryviewer__h____
 
+#include "nsCOMPtr.h"
 #include "nsIStreamListener.h"
 #include "nsIContentViewer.h"
 #include "nsIHTTPIndex.h"
 #include "nsIRDFService.h"
 #include "nsIRDFDataSource.h"
 #include "nsIRDFLiteral.h"
 #include "nsIDocumentLoaderFactory.h"
 #include "nsITimer.h"
-#include "nsISupportsArray.h"
 #include "nsXPIDLString.h"
 #include "nsIDirIndexListener.h"
 #include "nsIFTPChannel.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIURI.h"
 
+class nsIMutableArray;
+
 class nsDirectoryViewerFactory : public nsIDocumentLoaderFactory
 {
 public:
     nsDirectoryViewerFactory();
 
     // nsISupports interface
     NS_DECL_ISUPPORTS
     NS_DECL_NSIDOCUMENTLOADERFACTORY
@@ -65,18 +67,18 @@ private:
 protected:
     // We grab a reference to the content viewer container (which
     // indirectly owns us) so that we can insert ourselves as a global
     // in the script context _after_ the XUL doc has been embedded into
     // content viewer. We'll know that this has happened once we receive
     // an OnStartRequest() notification
 
     nsCOMPtr<nsIRDFDataSource>   mInner;
-    nsCOMPtr<nsISupportsArray>   mConnectionList;
-    nsCOMPtr<nsISupportsArray>   mNodeList;
+    nsCOMPtr<nsIMutableArray>    mConnectionList;
+    nsCOMPtr<nsIMutableArray>    mNodeList;
     nsCOMPtr<nsITimer>           mTimer;
     nsCOMPtr<nsIDirIndexParser>  mParser;
     nsCString mBaseURL;
     nsCString                    mEncoding;
     bool                         mBindToGlobalObject;
     nsIInterfaceRequestor*       mRequestor; // WEAK
     nsCOMPtr<nsIRDFResource>     mDirectory;