Unify singleton pattern in Profile class

1. Use unified function names `initInstance()` and `freeInstance()` and
make them public.
2. Add `freeInstance()` to avoid noise from memory leak detectors.
3. Let `instance()`return a pointer directly to avoid unnecessary
indirections when invoking functions.
This commit is contained in:
Chocobo1 2020-02-11 10:56:04 +08:00
parent 8b330e3ac0
commit 5de75eff05
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
9 changed files with 39 additions and 34 deletions

View file

@ -149,7 +149,7 @@ Application::Application(const QString &id, int &argc, char **argv)
const QString profileDir = portableModeEnabled
? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR)
: m_commandLineArgs.profileDir;
Profile::initialize(profileDir, m_commandLineArgs.configurationName,
Profile::initInstance(profileDir, m_commandLineArgs.configurationName,
(m_commandLineArgs.relativeFastresumePaths || portableModeEnabled));
Logger::initInstance();
@ -177,7 +177,7 @@ Application::Application(const QString &id, int &argc, char **argv)
Logger::instance()->addMessage(tr("Redundant command line flag detected: \"%1\". Portable mode implies relative fastresume.").arg("--relative-fastresume"), Log::WARNING); // to avoid translating the `--relative-fastresume` string
}
else {
Logger::instance()->addMessage(tr("Using config directory: %1").arg(Profile::instance().location(SpecialFolder::Config)));
Logger::instance()->addMessage(tr("Using config directory: %1").arg(Profile::instance()->location(SpecialFolder::Config)));
}
}
@ -764,6 +764,8 @@ void Application::cleanup()
}
#endif // DISABLE_GUI
Profile::freeInstance();
if (m_shutdownAct != ShutdownDialogAction::Exit) {
qDebug() << "Sending computer shutdown/suspend/hibernate signal...";
Utils::Misc::shutdownComputer(m_shutdownAct);