Bug 1403366 - Don't use nsDirectoryService::Create in nsDirectoryService::GetCurrentProcessDirectory. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 28 Sep 2017 08:46:43 +0900
changeset 384593 d6dc8ba8b0762681e7c0ed4005ca5a194d48b325
parent 384592 1e8554fbafadd2b1e403e6f8de91dfc1b2912d06
child 384594 3b49525269b130fc688913e76e5c14193d06b26b
push id32631
push userarchaeopteryx@coole-files.de
push dateThu, 05 Oct 2017 08:51:33 +0000
treeherdermozilla-central@66042a706980 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1403366
milestone58.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 1403366 - Don't use nsDirectoryService::Create in nsDirectoryService::GetCurrentProcessDirectory. r=froydnj Back in the day, there was no global with an already initialized DirectoryService. But now there is, and, in fact, GetCurrentProcessDirectory already errors out if that global is not set by the time it's called. All calling nsDirectoryService::Create achieves is doing the check again and calling QueryInterface, which we don't need to do anyways.
xpcom/io/nsDirectoryService.cpp
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -60,34 +60,22 @@ nsDirectoryService::GetCurrentProcessDir
   }
   *aFile = nullptr;
 
   //  Set the component registry location:
   if (!gService) {
     return NS_ERROR_FAILURE;
   }
 
-  nsresult rv;
-
-  nsCOMPtr<nsIProperties> dirService;
-  rv = nsDirectoryService::Create(nullptr,
-                                  NS_GET_IID(nsIProperties),
-                                  getter_AddRefs(dirService));  // needs to be around for life of product
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  if (dirService) {
-    nsCOMPtr<nsIFile> localFile;
-    dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
-                    getter_AddRefs(localFile));
-    if (localFile) {
-      localFile.forget(aFile);
-      return NS_OK;
-    }
+  nsCOMPtr<nsIFile> file;
+  gService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
+                getter_AddRefs(file));
+  if (file) {
+    file.forget(aFile);
+    return NS_OK;
   }
 
   RefPtr<nsLocalFile> localFile = new nsLocalFile;
 
 #ifdef XP_WIN
   wchar_t buf[MAX_PATH + 1];
   SetLastError(ERROR_SUCCESS);
   if (GetModuleFileNameW(0, buf, mozilla::ArrayLength(buf)) &&
@@ -116,17 +104,17 @@ nsDirectoryService::GetCurrentProcessDir
         // This will resolve the relative portion of the CFURL against it base, giving a full
         // path, which CFURLCopyFileSystemPath doesn't do.
         char buffer[PATH_MAX];
         if (CFURLGetFileSystemRepresentation(parentURL, true,
                                              (UInt8*)buffer, sizeof(buffer))) {
 #ifdef DEBUG_conrad
           printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
 #endif
-          rv = localFile->InitWithNativePath(nsDependentCString(buffer));
+          nsresult rv = localFile->InitWithNativePath(nsDependentCString(buffer));
           if (NS_SUCCEEDED(rv)) {
             localFile.forget(aFile);
           }
         }
         CFRelease(parentURL);
       }
       CFRelease(bundleURL);
     }