Browse Source

DownloadEngine: Use std::unique_ptr for btRegistry_

Tatsuhiro Tsujikawa 12 years ago
parent
commit
cc3cd8a58b
4 changed files with 10 additions and 10 deletions
  1. 6 6
      src/BtSetup.cc
  2. 1 1
      src/DownloadEngine.cc
  3. 2 2
      src/DownloadEngine.h
  4. 1 1
      src/RequestGroup.cc

+ 6 - 6
src/BtSetup.cc

@@ -101,12 +101,12 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
   auto torrentAttrs =
     bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
   bool metadataGetMode = torrentAttrs->metadata.empty();
-  const std::shared_ptr<BtRegistry>& btReg = e->getBtRegistry();
-  const std::shared_ptr<BtObject>& btObject = btReg->get(requestGroup->getGID());
-  const std::shared_ptr<PieceStorage>& pieceStorage = btObject->pieceStorage;
-  const std::shared_ptr<PeerStorage>& peerStorage = btObject->peerStorage;
-  const std::shared_ptr<BtRuntime>& btRuntime = btObject->btRuntime;
-  const std::shared_ptr<BtAnnounce>& 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<TrackerWatcherCommand>(e->newCUID(), requestGroup, e);

+ 1 - 1
src/DownloadEngine.cc

@@ -95,7 +95,7 @@ DownloadEngine::DownloadEngine(const std::shared_ptr<EventPoll>& eventPoll)
     lastRefresh_(0),
     cookieStorage_(new CookieStorage()),
 #ifdef ENABLE_BITTORRENT
-    btRegistry_(new BtRegistry()),
+    btRegistry_(make_unique<BtRegistry>()),
 #endif // ENABLE_BITTORRENT
 #ifdef HAVE_ARES_ADDR_NODE
     asyncDNSServers_(0),

+ 2 - 2
src/DownloadEngine.h

@@ -136,7 +136,7 @@ private:
   std::unique_ptr<CookieStorage> cookieStorage_;
 
 #ifdef ENABLE_BITTORRENT
-  std::shared_ptr<BtRegistry> btRegistry_;
+  std::unique_ptr<BtRegistry> btRegistry_;
 #endif // ENABLE_BITTORRENT
 
   CUIDCounter cuidCounter_;
@@ -305,7 +305,7 @@ public:
   const std::unique_ptr<CookieStorage>& getCookieStorage() const;
 
 #ifdef ENABLE_BITTORRENT
-  const std::shared_ptr<BtRegistry>& getBtRegistry() const
+  const std::unique_ptr<BtRegistry>& getBtRegistry() const
   {
     return btRegistry_;
   }

+ 1 - 1
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> 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.