diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index f3dbcd17..197f00db 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -145,30 +145,21 @@ void AbstractSingleDiskAdaptor::truncate(int64_t length) diskWriter_->truncate(length); } -std::shared_ptr +std::unique_ptr AbstractSingleDiskAdaptor::fileAllocationIterator() { switch(getFileAllocationMethod()) { #ifdef HAVE_SOME_FALLOCATE - case(DiskAdaptor::FILE_ALLOC_FALLOC): { - std::shared_ptr h - (new FallocFileAllocationIterator - (diskWriter_.get(), size() ,totalLength_)); - return h; - } + case(DiskAdaptor::FILE_ALLOC_FALLOC): + return make_unique + (diskWriter_.get(), size() ,totalLength_); #endif // HAVE_SOME_FALLOCATE - case(DiskAdaptor::FILE_ALLOC_TRUNC): { - std::shared_ptr h - (new TruncFileAllocationIterator - (diskWriter_.get(), size(), totalLength_)); - return h; - } - default: { - std::shared_ptr h - (new AdaptiveFileAllocationIterator - (diskWriter_.get(), size(), totalLength_)); - return h; - } + case(DiskAdaptor::FILE_ALLOC_TRUNC): + return make_unique + (diskWriter_.get(), size(), totalLength_); + default: + return make_unique + (diskWriter_.get(), size(), totalLength_); } } diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h index 4d27b815..6a6ea3de 100644 --- a/src/AbstractSingleDiskAdaptor.h +++ b/src/AbstractSingleDiskAdaptor.h @@ -73,7 +73,7 @@ public: virtual void truncate(int64_t length); - virtual std::shared_ptr fileAllocationIterator(); + virtual std::unique_ptr fileAllocationIterator(); // Make sure that DiskWriter is set before calling this function. virtual void enableReadOnly(); diff --git a/src/AdaptiveFileAllocationIterator.cc b/src/AdaptiveFileAllocationIterator.cc index f4a116ef..36a2e928 100644 --- a/src/AdaptiveFileAllocationIterator.cc +++ b/src/AdaptiveFileAllocationIterator.cc @@ -38,6 +38,7 @@ #include "RecoverableException.h" #include "LogFactory.h" #include "Logger.h" +#include "a2functional.h" #ifdef HAVE_FALLOCATE # include "FallocFileAllocationIterator.h" #endif // HAVE_FALLOCATE @@ -66,20 +67,20 @@ void AdaptiveFileAllocationIterator::allocateChunk() offset_ += len; } A2_LOG_DEBUG("File system supports fallocate."); - allocator_.reset - (new FallocFileAllocationIterator(stream_, offset_, totalLength_)); + allocator_ = make_unique + (stream_, offset_, totalLength_); } catch(RecoverableException& e) { A2_LOG_DEBUG("File system does not support fallocate."); - std::shared_ptr salloc - (new SingleFileAllocationIterator(stream_, offset_, totalLength_)); + auto salloc = make_unique + (stream_, offset_, totalLength_); salloc->init(); - allocator_ = salloc; + allocator_ = std::move(salloc); } #else // !HAVE_FALLOCATE - std::shared_ptr salloc - (new SingleFileAllocationIterator(stream_, offset_, totalLength_)); + auto salloc = make_unique + (stream_, offset_, totalLength_); salloc->init(); - allocator_ = salloc; + allocator_ = std::move(salloc); #endif // !HAVE_FALLOCATE allocator_->allocateChunk(); } else { diff --git a/src/AdaptiveFileAllocationIterator.h b/src/AdaptiveFileAllocationIterator.h index 6a3fd36c..f66b6b0f 100644 --- a/src/AdaptiveFileAllocationIterator.h +++ b/src/AdaptiveFileAllocationIterator.h @@ -46,7 +46,7 @@ class BinaryStream; class AdaptiveFileAllocationIterator:public FileAllocationIterator { private: - std::shared_ptr allocator_; + std::unique_ptr allocator_; BinaryStream* stream_; diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index 6e46fa4e..2e792763 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -78,12 +78,12 @@ public: fileEntries_.assign(first, last); } - const std::vector >& getFileEntries() const + const std::vector>& getFileEntries() const { return fileEntries_; } - virtual std::shared_ptr fileAllocationIterator() = 0; + virtual std::unique_ptr fileAllocationIterator() = 0; virtual void enableReadOnly() {} diff --git a/src/FileAllocationEntry.cc b/src/FileAllocationEntry.cc index 4a580398..e276e40e 100644 --- a/src/FileAllocationEntry.cc +++ b/src/FileAllocationEntry.cc @@ -42,9 +42,10 @@ namespace aria2 { FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup, - std::unique_ptr nextCommand): - RequestGroupEntry(requestGroup, std::move(nextCommand)), - fileAllocationIterator_(requestGroup->getPieceStorage()->getDiskAdaptor()->fileAllocationIterator()) + std::unique_ptr nextCommand) + : RequestGroupEntry{requestGroup, std::move(nextCommand)}, + fileAllocationIterator_{requestGroup->getPieceStorage()->getDiskAdaptor() + ->fileAllocationIterator()} {} FileAllocationEntry:: ~FileAllocationEntry() diff --git a/src/FileAllocationEntry.h b/src/FileAllocationEntry.h index 6811f56f..60893f49 100644 --- a/src/FileAllocationEntry.h +++ b/src/FileAllocationEntry.h @@ -50,7 +50,7 @@ class DownloadEngine; class FileAllocationEntry : public RequestGroupEntry, public ProgressAwareEntry { private: - std::shared_ptr fileAllocationIterator_; + std::unique_ptr fileAllocationIterator_; public: FileAllocationEntry(RequestGroup* requestGroup, std::unique_ptr nextCommand = diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 147160f0..048e523b 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -481,10 +481,10 @@ int64_t MultiDiskAdaptor::size() return size; } -std::shared_ptr +std::unique_ptr MultiDiskAdaptor::fileAllocationIterator() { - return std::make_shared(this); + return make_unique(this); } void MultiDiskAdaptor::enableReadOnly() diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h index 59c239cd..bf85da90 100644 --- a/src/MultiDiskAdaptor.h +++ b/src/MultiDiskAdaptor.h @@ -150,7 +150,7 @@ public: virtual int64_t size(); - virtual std::shared_ptr fileAllocationIterator(); + virtual std::unique_ptr fileAllocationIterator(); virtual void enableReadOnly();