зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1525086 - Part 4 - Cache the result of nsMacUtilsImpl::GetAppPath r=Alex_Gaynor
Cache the result of nsMacUtilsImpl::GetAppPath() to avoid doing I/O on repeated calls. Differential Revision: https://phabricator.services.mozilla.com/D22410 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9eeac5a5a2
Коммит
35ea11e89d
|
@ -7,6 +7,7 @@
|
|||
#include "nsMacUtilsImpl.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFile.h"
|
||||
|
@ -18,6 +19,13 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsMacUtilsImpl, nsIMacUtils)
|
||||
|
||||
using mozilla::StaticMutexAutoLock;
|
||||
|
||||
#if defined(MOZ_SANDBOX)
|
||||
StaticAutoPtr<nsCString> nsMacUtilsImpl::sCachedAppPath;
|
||||
StaticMutex nsMacUtilsImpl::sCachedAppPathMutex;
|
||||
#endif
|
||||
|
||||
nsresult nsMacUtilsImpl::GetArchString(nsAString& aArchString) {
|
||||
if (!mBinaryArchs.IsEmpty()) {
|
||||
aArchString.Assign(mBinaryArchs);
|
||||
|
@ -134,6 +142,12 @@ nsMacUtilsImpl::GetIsTranslated(bool* aIsTranslated) {
|
|||
// executable. We don't rely on the actual .app extension to allow for the
|
||||
// bundle being renamed.
|
||||
bool nsMacUtilsImpl::GetAppPath(nsCString& aAppPath) {
|
||||
StaticMutexAutoLock lock(sCachedAppPathMutex);
|
||||
if (sCachedAppPath) {
|
||||
aAppPath.Assign(*sCachedAppPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsAutoCString appPath;
|
||||
nsAutoCString appBinaryPath(
|
||||
(CommandLine::ForCurrentProcess()->argv()[0]).c_str());
|
||||
|
@ -179,6 +193,11 @@ bool nsMacUtilsImpl::GetAppPath(nsCString& aAppPath) {
|
|||
}
|
||||
app->GetNativePath(aAppPath);
|
||||
|
||||
if (!sCachedAppPath) {
|
||||
sCachedAppPath = new nsCString(aAppPath);
|
||||
ClearOnShutdown(&sCachedAppPath);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
#include "nsIMacUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
using mozilla::StaticAutoPtr;
|
||||
using mozilla::StaticMutex;
|
||||
|
||||
class nsMacUtilsImpl final : public nsIMacUtils {
|
||||
public:
|
||||
|
@ -34,6 +39,13 @@ class nsMacUtilsImpl final : public nsIMacUtils {
|
|||
// A string containing a "-" delimited list of architectures
|
||||
// in our binary.
|
||||
nsString mBinaryArchs;
|
||||
|
||||
#if defined(MOZ_SANDBOX)
|
||||
// Cache the appDir returned from GetAppPath to avoid doing I/O
|
||||
static StaticAutoPtr<nsCString> sCachedAppPath;
|
||||
// For thread safe setting/checking of sCachedAppPath
|
||||
static StaticMutex sCachedAppPathMutex;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Global singleton service
|
||||
|
|
Загрузка…
Ссылка в новой задаче