From cc3cd8a58b11d639c327ca6debb041747c3828d6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 6 Jul 2013 18:42:57 +0900 Subject: [PATCH] DownloadEngine: Use std::unique_ptr for btRegistry_ --- src/BtSetup.cc | 12 ++++++------ src/DownloadEngine.cc | 2 +- src/DownloadEngine.h | 4 ++-- src/RequestGroup.cc | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 595c2987..31ee458e 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -101,12 +101,12 @@ void BtSetup::setup(std::vector>& commands, auto torrentAttrs = bittorrent::getTorrentAttrs(requestGroup->getDownloadContext()); bool metadataGetMode = torrentAttrs->metadata.empty(); - const std::shared_ptr& btReg = e->getBtRegistry(); - const std::shared_ptr& btObject = btReg->get(requestGroup->getGID()); - const std::shared_ptr& pieceStorage = btObject->pieceStorage; - const std::shared_ptr& peerStorage = btObject->peerStorage; - const std::shared_ptr& btRuntime = btObject->btRuntime; - const std::shared_ptr& btAnnounce = btObject->btAnnounce; + auto& btReg = e->getBtRegistry(); + auto& btObject = btReg->get(requestGroup->getGID()); + auto& pieceStorage = btObject->pieceStorage; + auto& peerStorage = btObject->peerStorage; + auto& btRuntime = btObject->btRuntime; + auto& btAnnounce = btObject->btAnnounce; // commands { auto c = make_unique(e->newCUID(), requestGroup, e); diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index ba7adead..3f5d4484 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -95,7 +95,7 @@ DownloadEngine::DownloadEngine(const std::shared_ptr& eventPoll) lastRefresh_(0), cookieStorage_(new CookieStorage()), #ifdef ENABLE_BITTORRENT - btRegistry_(new BtRegistry()), + btRegistry_(make_unique()), #endif // ENABLE_BITTORRENT #ifdef HAVE_ARES_ADDR_NODE asyncDNSServers_(0), diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index 75b396f8..4f05204d 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -136,7 +136,7 @@ private: std::unique_ptr cookieStorage_; #ifdef ENABLE_BITTORRENT - std::shared_ptr btRegistry_; + std::unique_ptr btRegistry_; #endif // ENABLE_BITTORRENT CUIDCounter cuidCounter_; @@ -305,7 +305,7 @@ public: const std::unique_ptr& getCookieStorage() const; #ifdef ENABLE_BITTORRENT - const std::shared_ptr& getBtRegistry() const + const std::unique_ptr& getBtRegistry() const { return btRegistry_; } diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index ff0ff5bb..aa548611 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -289,7 +289,7 @@ void RequestGroup::createInitialCommand throw DOWNLOAD_FAILURE_EXCEPTION ("Cancel BitTorrent download in dry-run context."); } - std::shared_ptr btRegistry = e->getBtRegistry(); + auto& btRegistry = e->getBtRegistry(); if(btRegistry->getDownloadContext(torrentAttrs->infoHash)) { // TODO If metadataGetMode == false and each FileEntry has // URI, then go without BT.