Selaa lähdekoodia

Use std::unique_ptr for IteratableValidator

Tatsuhiro Tsujikawa 12 vuotta sitten
vanhempi
commit
c9e58779e1

+ 4 - 4
src/CheckIntegrityEntry.cc

@@ -45,8 +45,8 @@
 namespace aria2 {
 
 CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup,
-                                         std::unique_ptr<Command> nextCommand):
-  RequestGroupEntry(requestGroup, std::move(nextCommand))
+                                         std::unique_ptr<Command> nextCommand)
+  : RequestGroupEntry{requestGroup, std::move(nextCommand)}
 {}
 
 CheckIntegrityEntry::~CheckIntegrityEntry() {}
@@ -97,9 +97,9 @@ void CheckIntegrityEntry::proceedFileAllocation
 }
 
 void CheckIntegrityEntry::setValidator
-(const std::shared_ptr<IteratableValidator>& validator)
+(std::unique_ptr<IteratableValidator> validator)
 {
-  validator_ = validator;
+  validator_ = std::move(validator);
 }
 
 } // namespace aria2

+ 2 - 2
src/CheckIntegrityEntry.h

@@ -51,9 +51,9 @@ class FileAllocationEntry;
 class CheckIntegrityEntry : public RequestGroupEntry,
                             public ProgressAwareEntry {
 private:
-  std::shared_ptr<IteratableValidator> validator_;
+  std::unique_ptr<IteratableValidator> validator_;
 protected:
-  void setValidator(const std::shared_ptr<IteratableValidator>& validator);
+  void setValidator(std::unique_ptr<IteratableValidator> validator);
 
   void proceedFileAllocation(std::vector<std::unique_ptr<Command>>& commands,
                              const std::shared_ptr<FileAllocationEntry>& entry,

+ 8 - 7
src/ChecksumCheckIntegrityEntry.cc

@@ -45,9 +45,10 @@
 namespace aria2 {
 
 ChecksumCheckIntegrityEntry::ChecksumCheckIntegrityEntry
-(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand):
-  CheckIntegrityEntry(requestGroup, std::move(nextCommand)),
-  redownload_(false) {}
+(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand)
+  : CheckIntegrityEntry{requestGroup, std::move(nextCommand)},
+    redownload_{false}
+{}
 
 ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
 
@@ -60,11 +61,11 @@ bool ChecksumCheckIntegrityEntry::isValidationReady()
 
 void ChecksumCheckIntegrityEntry::initValidator()
 {
-  std::shared_ptr<IteratableChecksumValidator> validator
-    (new IteratableChecksumValidator(getRequestGroup()->getDownloadContext(),
-                                     getRequestGroup()->getPieceStorage()));
+  auto validator = make_unique<IteratableChecksumValidator>
+    (getRequestGroup()->getDownloadContext(),
+     getRequestGroup()->getPieceStorage());
   validator->init();
-  setValidator(validator);
+  setValidator(std::move(validator));
 }
 
 void

+ 8 - 7
src/PieceHashCheckIntegrityEntry.cc

@@ -37,13 +37,15 @@
 #include "IteratableChunkChecksumValidator.h"
 #include "DownloadContext.h"
 #include "PieceStorage.h"
+#include "a2functional.h"
 
 namespace aria2 {
 
 PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry
 (RequestGroup* requestGroup,
- std::unique_ptr<Command> nextCommand):
-  CheckIntegrityEntry(requestGroup, std::move(nextCommand)) {}
+ std::unique_ptr<Command> nextCommand)
+  : CheckIntegrityEntry{requestGroup, std::move(nextCommand)}
+{}
 
 PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {}
 
@@ -57,12 +59,11 @@ bool PieceHashCheckIntegrityEntry::isValidationReady()
 void PieceHashCheckIntegrityEntry::initValidator()
 {
 #ifdef ENABLE_MESSAGE_DIGEST
-  std::shared_ptr<IteratableChunkChecksumValidator> validator
-    (new IteratableChunkChecksumValidator
-     (getRequestGroup()->getDownloadContext(),
-      getRequestGroup()->getPieceStorage()));
+  auto validator = make_unique<IteratableChunkChecksumValidator>
+    (getRequestGroup()->getDownloadContext(),
+     getRequestGroup()->getPieceStorage());
   validator->init();
-  setValidator(validator);
+  setValidator(std::move(validator));
 #endif // ENABLE_MESSAGE_DIGEST
 }