From 2157e500ef01e96ea1fcdb7bb7a33cf0cb1deae7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 5 Mar 2020 00:39:41 +0800 Subject: [PATCH] Use helper functions to construct smart pointers --- src/app/main.cpp | 4 ++-- src/base/bittorrent/private/nativesessionextension.cpp | 2 +- src/base/search/searchpluginmanager.cpp | 2 +- src/base/utils/fs.cpp | 2 +- src/base/utils/misc.cpp | 2 +- src/base/utils/misc.h | 2 +- src/gui/addnewtorrentdialog.cpp | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 2a9f84862..50a7d7604 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) try { // Create Application const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString(); - std::unique_ptr app(new Application(appId, argc, argv)); + auto app = std::make_unique(appId, argc, argv); const QBtCommandLineParameters params = app->commandLineArgs(); @@ -258,7 +258,7 @@ int main(int argc, char *argv[]) if (params.shouldDaemonize) { app.reset(); // Destroy current application if (daemon(1, 0) == 0) { - app.reset(new Application(appId, argc, argv)); + app = std::make_unique(appId, argc, argv); if (app->isRunning()) { // Another instance had time to start. return EXIT_FAILURE; diff --git a/src/base/bittorrent/private/nativesessionextension.cpp b/src/base/bittorrent/private/nativesessionextension.cpp index f1bf0d55b..8ce4e9633 100644 --- a/src/base/bittorrent/private/nativesessionextension.cpp +++ b/src/base/bittorrent/private/nativesessionextension.cpp @@ -60,7 +60,7 @@ std::shared_ptr NativeSessionExtension::new_torrent(const lt #else boost::shared_ptr NativeSessionExtension::new_torrent(const lt::torrent_handle &torrentHandle, void *) { - return boost::shared_ptr {new NativeTorrentExtension {torrentHandle}}; + return boost::make_shared(torrentHandle); } #endif diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index 9dae06b81..3d68aa0b5 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -457,7 +457,7 @@ void SearchPluginManager::update() if (!engineElem.isNull()) { const QString pluginName = engineElem.tagName(); - std::unique_ptr plugin {new PluginInfo {}}; + auto plugin = std::make_unique(); plugin->name = pluginName; plugin->version = getPluginVersion(pluginPath(pluginName)); plugin->fullName = engineElem.elementsByTagName("name").at(0).toElement().text(); diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index 77404c25d..9f2314e53 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -327,7 +327,7 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path) { #if defined(Q_OS_WIN) const std::wstring pathW {path.toStdWString()}; - std::unique_ptr volumePath {new wchar_t[path.length() + 1] {}}; + auto volumePath = std::make_unique(path.length() + 1); if (!::GetVolumePathNameW(pathW.c_str(), volumePath.get(), (path.length() + 1))) return false; diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index a8e4386bc..c3f4015c9 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -126,7 +126,7 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action) } else { const QString msg = QCoreApplication::translate("misc", "qBittorrent will shutdown the computer now because all downloads are complete."); - std::unique_ptr msgWchar(new wchar_t[msg.length() + 1] {}); + auto msgWchar = std::make_unique(msg.length() + 1); msg.toWCharArray(msgWchar.get()); ::InitiateSystemShutdownW(nullptr, msgWchar.get(), 10, true, false); } diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index 4aa57c8ca..33d65abdc 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -99,7 +99,7 @@ namespace Utils path += source; - std::unique_ptr pathWchar(new wchar_t[path.length() + 1] {}); + auto pathWchar = std::make_unique(path.length() + 1); path.toWCharArray(pathWchar.get()); return reinterpret_cast( diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index dae5d960e..5a93cc697 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -268,7 +268,7 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &torrentPath) return false; } - m_torrentGuard.reset(new TorrentFileGuard(decodedPath)); + m_torrentGuard = std::make_unique(decodedPath); return loadTorrentImpl(); } @@ -310,7 +310,7 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri) return false; } - m_torrentGuard.reset(new TorrentFileGuard(QString())); + m_torrentGuard = std::make_unique(); m_hash = magnetUri.hash(); // Prevent showing the dialog if download is already present if (BitTorrent::Session::instance()->isKnownTorrent(m_hash)) { @@ -678,7 +678,7 @@ void AddNewTorrentDialog::handleDownloadFinished(const Net::DownloadResult &resu return; } - m_torrentGuard.reset(new TorrentFileGuard); + m_torrentGuard = std::make_unique(); if (loadTorrentImpl()) open();