Bug 783869 part 1 - Convert nsDirectoryService::mProviders to nsTArray; r=bsmedberg
authorAryeh Gregor <ayg@aryeh.name>
Tue, 21 Aug 2012 15:02:37 +0300
changeset 104662 f17fe6cdea2a50008c1265c290987f59f1ca187f
parent 104661 090511685ed4ceed095dc3f2d14d5c93932737ff
child 104663 54a5072fe77507a9ebefb1cc0004bdc56ca4301e
push id14624
push userayg@aryeh.name
push dateSun, 09 Sep 2012 11:06:11 +0000
treeherdermozilla-inbound@5642666e6f9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs783869
milestone18.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 783869 part 1 - Convert nsDirectoryService::mProviders to nsTArray; r=bsmedberg
xpcom/io/nsDirectoryService.cpp
xpcom/io/nsDirectoryService.h
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -258,38 +258,27 @@ nsDirectoryService::Init()
 }
 
 nsresult
 nsDirectoryService::RealInit()
 {
     NS_ASSERTION(!gService, 
                  "nsDirectoryService::RealInit Mustn't initialize twice!");
 
-    nsresult rv;
-
     nsRefPtr<nsDirectoryService> self = new nsDirectoryService();
     if (!self)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    rv = NS_NewISupportsArray(getter_AddRefs(((nsDirectoryService*) self)->mProviders));
-    if (NS_FAILED(rv))
-        return rv;
-
     NS_RegisterStaticAtoms(directory_atoms);
     
     // Let the list hold the only reference to the provider.
     nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider;
     if (!defaultProvider)
         return NS_ERROR_OUT_OF_MEMORY;
-    // AppendElement returns true for success.
-    rv = static_cast<bool>(((nsDirectoryService*) self)
-                           ->mProviders->AppendElement(defaultProvider))
-        ? NS_OK : NS_ERROR_FAILURE;
-    if (NS_FAILED(rv))
-        return rv;
+    self->mProviders.AppendElement(defaultProvider);
 
     self.swap(gService);
     return NS_OK;
 }
 
 bool
 nsDirectoryService::ReleaseValues(nsHashKey* key, void* data, void* closure)
 {
@@ -403,17 +392,21 @@ nsDirectoryService::Get(const char* prop
 
         cachedFile->Clone(getter_AddRefs(cloneFile));
         return cloneFile->QueryInterface(uuid, result);
     }
 
     // it is not one of our defaults, lets check any providers
     FileData fileData(prop, uuid);
 
-    mProviders->EnumerateBackwards(FindProviderFile, &fileData);
+    for (int32_t i = mProviders.Length() - 1; i >= 0; i--) {
+        if (!FindProviderFile(mProviders[i], &fileData)) {
+            break;
+        }
+    }
     if (fileData.data)
     {
         if (fileData.persistent)
         {
             Set(prop, static_cast<nsIFile*>(fileData.data));
         }
         nsresult rv = (fileData.data)->QueryInterface(uuid, result);
         NS_RELEASE(fileData.data);  // addref occurs in FindProviderFile()
@@ -475,28 +468,21 @@ nsDirectoryService::Has(const char *prop
     }
     
     return rv;
 }
 
 NS_IMETHODIMP
 nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider *prov)
 {
-    nsresult rv;
     if (!prov)
         return NS_ERROR_FAILURE;
-    if (!mProviders)
-        return NS_ERROR_NOT_INITIALIZED;
 
-    nsCOMPtr<nsISupports> supports = do_QueryInterface(prov, &rv);
-    if (NS_FAILED(rv)) return rv;
-
-    // AppendElement returns true for success.
-    return static_cast<bool>(mProviders->AppendElement(supports))
-        ? NS_OK : NS_ERROR_FAILURE;
+    mProviders.AppendElement(prov);
+    return NS_OK;
 }
 
 void
 nsDirectoryService::RegisterCategoryProviders()
 {
     nsCOMPtr<nsICategoryManager> catman
         (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
     if (!catman)
@@ -524,28 +510,21 @@ nsDirectoryService::RegisterCategoryProv
                 RegisterProvider(provider);
         }
     }
 }
 
 NS_IMETHODIMP
 nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider *prov)
 {
-    nsresult rv;
     if (!prov)
         return NS_ERROR_FAILURE;
-    if (!mProviders)
-        return NS_ERROR_NOT_INITIALIZED;
 
-    nsCOMPtr<nsISupports> supports = do_QueryInterface(prov, &rv);
-    if (NS_FAILED(rv)) return rv;
-
-    // RemoveElement returns true for success.
-    return static_cast<bool>(mProviders->RemoveElement(supports))
-        ? NS_OK : NS_ERROR_FAILURE;
+    mProviders.RemoveElement(prov);
+    return NS_OK;
 }
 
 // DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
 // This is meant to be a place of xpcom or system specific file locations, not
 // application specific locations.  If you need the later, register a callback for
 // your application.  
 
 NS_IMETHODIMP
--- a/xpcom/io/nsDirectoryService.h
+++ b/xpcom/io/nsDirectoryService.h
@@ -45,17 +45,17 @@ class nsDirectoryService MOZ_FINAL : pub
 
   static nsDirectoryService* gService;
 
 private:
     nsresult GetCurrentProcessDirectory(nsIFile** aFile);
     
     static bool ReleaseValues(nsHashKey* key, void* data, void* closure);
     nsSupportsHashtable mHashtable;
-    nsCOMPtr<nsISupportsArray> mProviders;
+    nsTArray<nsCOMPtr<nsIDirectoryServiceProvider> > mProviders;
 
 public:
 
 #define DIR_ATOM(name_, value_) static nsIAtom* name_;
 #include "nsDirectoryServiceAtomList.h"
 #undef DIR_ATOM
 
 };