mirror of https://github.com/aria2/aria2
Return nullptr directly where std::shared_ptr is expected
The constructor of std::shared_ptr which takes nullptr is not explicit so we can return nullptr directly.pull/103/head
parent
107de58997
commit
0cdeaa8177
|
@ -351,7 +351,7 @@ std::shared_ptr<ServerStat> AdaptiveURISelector::getServerStats
|
|||
std::string protocol = uri::getFieldString(us, USR_SCHEME, uri.c_str());
|
||||
return serverStatMan_->find(host, protocol);
|
||||
} else {
|
||||
return std::shared_ptr<ServerStat>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
|
|||
if (hashType == "md5") {
|
||||
return std::shared_ptr<MessageDigestImpl>(new MessageDigestMD5());
|
||||
}
|
||||
return std::shared_ptr<MessageDigestImpl>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MessageDigestImpl::supports(const std::string& hashType)
|
||||
|
|
|
@ -235,7 +235,7 @@ std::shared_ptr<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const s
|
|||
std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
|
||||
if(itr == nodes_.end() ||
|
||||
(*itr)->getIPAddress() != ipaddr || (*itr)->getPort() != port) {
|
||||
return std::shared_ptr<DHTNode>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return *itr;
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ std::shared_ptr<DHTNode> DHTBucket::getLRUQuestionableNode() const
|
|||
std::deque<std::shared_ptr<DHTNode> >::const_iterator i =
|
||||
std::find_if(nodes_.begin(), nodes_.end(), FindQuestionableNode());
|
||||
if(i == nodes_.end()) {
|
||||
return std::shared_ptr<DHTNode>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return *i;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ std::shared_ptr<DHTTask>
|
|||
DHTTaskFactoryImpl::createPeerAnnounceTask(const unsigned char* infoHash)
|
||||
{
|
||||
// TODO
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<DHTTask>
|
||||
|
|
|
@ -205,7 +205,7 @@ std::shared_ptr<UDPTrackerRequest> DefaultBtAnnounce::createUDPTrackerRequest
|
|||
(const std::string& remoteAddr, uint16_t remotePort, uint16_t localPort)
|
||||
{
|
||||
if(!adjustAnnounceList()) {
|
||||
return std::shared_ptr<UDPTrackerRequest>();
|
||||
return nullptr;
|
||||
}
|
||||
NetStat& stat = downloadContext_->getNetStat();
|
||||
int64_t left =
|
||||
|
|
|
@ -123,7 +123,7 @@ std::shared_ptr<BtMessage> DefaultBtInteractive::receiveHandshake(bool quickRepl
|
|||
std::shared_ptr<BtHandshakeMessage> message =
|
||||
btMessageReceiver_->receiveHandshake(quickReply);
|
||||
if(!message) {
|
||||
return std::shared_ptr<BtMessage>();
|
||||
return nullptr;
|
||||
}
|
||||
if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
|
||||
PEER_ID_LENGTH) == 0) {
|
||||
|
|
|
@ -119,7 +119,7 @@ std::shared_ptr<BtMessage> DefaultBtMessageReceiver::receiveMessage() {
|
|||
size_t dataLength = 0;
|
||||
// Give 0 to PeerConnection::receiveMessage() to prevent memcpy.
|
||||
if(!peerConnection_->receiveMessage(0, dataLength)) {
|
||||
return std::shared_ptr<BtMessage>();
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<BtMessage> msg =
|
||||
messageFactory_->createBtMessage(peerConnection_->getMsgPayloadBuffer(),
|
||||
|
|
|
@ -225,7 +225,7 @@ void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
|
|||
std::shared_ptr<Peer> DefaultPeerStorage::checkoutPeer(cuid_t cuid)
|
||||
{
|
||||
if(!isPeerAvailable()) {
|
||||
return std::shared_ptr<Peer>();
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<Peer> peer = unusedPeers_.front();
|
||||
unusedPeers_.pop_front();
|
||||
|
|
|
@ -328,7 +328,7 @@ DefaultPieceStorage::getMissingPiece
|
|||
std::vector<std::shared_ptr<Piece> > pieces;
|
||||
getMissingPiece(pieces, 1, peer, cuid);
|
||||
if(pieces.empty()) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return pieces.front();
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::getMissingPiece
|
|||
std::vector<std::shared_ptr<Piece> > pieces;
|
||||
getMissingPiece(pieces, 1, peer, excludedIndexes, cuid);
|
||||
if(pieces.empty()) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return pieces.front();
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::getMissingFastPiece
|
|||
std::vector<std::shared_ptr<Piece> > pieces;
|
||||
getMissingFastPiece(pieces, 1, peer, cuid);
|
||||
if(pieces.empty()) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return pieces.front();
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::getMissingFastPiece
|
|||
std::vector<std::shared_ptr<Piece> > pieces;
|
||||
getMissingFastPiece(pieces, 1, peer, excludedIndexes, cuid);
|
||||
if(pieces.empty()) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return pieces.front();
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::getMissingPiece
|
|||
(index, minSplitSize, ignoreBitfield, length)) {
|
||||
return checkOutPiece(index, cuid);
|
||||
} else {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::getMissingPiece
|
|||
cuid_t cuid)
|
||||
{
|
||||
if(hasPiece(index) || isPieceUsed(index)) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return checkOutPiece(index, cuid);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ DownloadContext::findFileEntryByOffset(int64_t offset) const
|
|||
{
|
||||
if(fileEntries_.empty() ||
|
||||
(offset > 0 && fileEntries_.back()->getLastOffset() <= offset)) {
|
||||
return std::shared_ptr<FileEntry>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<FileEntry> obj(new FileEntry());
|
||||
|
@ -222,7 +222,7 @@ DownloadContext::getFirstRequestedFileEntry() const
|
|||
return *i;
|
||||
}
|
||||
}
|
||||
return std::shared_ptr<FileEntry>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t DownloadContext::countRequestedFileEntry() const
|
||||
|
|
|
@ -221,12 +221,12 @@ FileEntry::findFasterRequest(const std::shared_ptr<Request>& base)
|
|||
const int startupIdleTime = 10;
|
||||
if(requestPool_.empty() ||
|
||||
lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
||||
return std::shared_ptr<Request>();
|
||||
return nullptr;
|
||||
}
|
||||
const std::shared_ptr<PeerStat>& fastest =
|
||||
(*requestPool_.begin())->getPeerStat();
|
||||
if(!fastest) {
|
||||
return std::shared_ptr<Request>();
|
||||
return nullptr;
|
||||
}
|
||||
const std::shared_ptr<PeerStat>& basestat = base->getPeerStat();
|
||||
// TODO hard coded value. See PREF_STARTUP_IDLE_TIME
|
||||
|
@ -241,7 +241,7 @@ FileEntry::findFasterRequest(const std::shared_ptr<Request>& base)
|
|||
lastFasterReplace_ = global::wallclock();
|
||||
return fastestRequest;
|
||||
}
|
||||
return std::shared_ptr<Request>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Request>
|
||||
|
@ -253,7 +253,7 @@ FileEntry::findFasterRequest
|
|||
const int startupIdleTime = 10;
|
||||
const int SPEED_THRESHOLD = 20*1024;
|
||||
if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
||||
return std::shared_ptr<Request>();
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<std::string> inFlightHosts;
|
||||
enumerateInFlightHosts(inFlightRequests_.begin(), inFlightRequests_.end(),
|
||||
|
@ -307,7 +307,7 @@ FileEntry::findFasterRequest
|
|||
return fastestRequest;
|
||||
}
|
||||
A2_LOG_DEBUG("No faster server found.");
|
||||
return std::shared_ptr<Request>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void FileEntry::storePool(const std::shared_ptr<Request>& request)
|
||||
|
|
|
@ -287,7 +287,7 @@ std::shared_ptr<FileEntry> getFirstRequestedFileEntry
|
|||
return *first;
|
||||
}
|
||||
}
|
||||
return std::shared_ptr<FileEntry>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Counts the number of files selected in the given iterator range
|
||||
|
|
|
@ -129,7 +129,7 @@ createMethod(const std::string& methodName)
|
|||
} else if(methodName == SystemMulticallRpcMethod::getMethodName()) {
|
||||
return std::shared_ptr<RpcMethod>(new SystemMulticallRpcMethod());
|
||||
} else {
|
||||
return std::shared_ptr<RpcMethod>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -132,7 +132,7 @@ std::shared_ptr<Segment> SegmentMan::checkoutSegment
|
|||
(cuid_t cuid, const std::shared_ptr<Piece>& piece)
|
||||
{
|
||||
if(!piece) {
|
||||
return std::shared_ptr<Segment>();
|
||||
return nullptr;
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Attach segment#%lu to CUID#%" PRId64 ".",
|
||||
static_cast<unsigned long>(piece->getIndex()),
|
||||
|
@ -241,7 +241,7 @@ void SegmentMan::getSegment
|
|||
std::shared_ptr<Segment> SegmentMan::getSegmentWithIndex
|
||||
(cuid_t cuid, size_t index) {
|
||||
if(index > 0 && downloadContext_->getNumPieces() <= index) {
|
||||
return std::shared_ptr<Segment>();
|
||||
return nullptr;
|
||||
}
|
||||
return checkoutSegment(cuid, pieceStorage_->getMissingPiece(index, cuid));
|
||||
}
|
||||
|
@ -250,14 +250,14 @@ std::shared_ptr<Segment> SegmentMan::getCleanSegmentIfOwnerIsIdle
|
|||
(cuid_t cuid, size_t index)
|
||||
{
|
||||
if(index > 0 && downloadContext_->getNumPieces() <= index) {
|
||||
return std::shared_ptr<Segment>();
|
||||
return nullptr;
|
||||
}
|
||||
for(SegmentEntries::const_iterator itr = usedSegmentEntries_.begin(),
|
||||
eoi = usedSegmentEntries_.end(); itr != eoi; ++itr) {
|
||||
const std::shared_ptr<SegmentEntry>& segmentEntry = *itr;
|
||||
if(segmentEntry->segment->getIndex() == index) {
|
||||
if(segmentEntry->segment->getWrittenLength() > 0) {
|
||||
return std::shared_ptr<Segment>();
|
||||
return nullptr;
|
||||
}
|
||||
if(segmentEntry->cuid == cuid) {
|
||||
return segmentEntry->segment;
|
||||
|
@ -268,11 +268,11 @@ std::shared_ptr<Segment> SegmentMan::getCleanSegmentIfOwnerIsIdle
|
|||
cancelSegment(owner);
|
||||
return getSegmentWithIndex(cuid, index);
|
||||
} else {
|
||||
return std::shared_ptr<Segment>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::shared_ptr<Segment>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SegmentMan::cancelSegmentInternal
|
||||
|
@ -399,7 +399,7 @@ std::shared_ptr<PeerStat> SegmentMan::getPeerStat(cuid_t cuid) const
|
|||
return *i;
|
||||
}
|
||||
}
|
||||
return std::shared_ptr<PeerStat>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -62,7 +62,7 @@ std::shared_ptr<ServerStat> ServerStatMan::find(const std::string& hostname,
|
|||
std::shared_ptr<ServerStat> ss(new ServerStat(hostname, protocol));
|
||||
ServerStatSet::iterator i = serverStats_.find(ss);
|
||||
if(i == serverStats_.end()) {
|
||||
return std::shared_ptr<ServerStat>();
|
||||
return nullptr;
|
||||
} else {
|
||||
return *i;
|
||||
}
|
||||
|
|
|
@ -142,13 +142,13 @@ std::shared_ptr<Piece> UnknownLengthPieceStorage::getMissingPiece
|
|||
cuid_t cuid)
|
||||
{
|
||||
if(downloadFinished_) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
}
|
||||
if(!piece_) {
|
||||
piece_.reset(new Piece());
|
||||
return piece_;
|
||||
} else {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ std::shared_ptr<Piece> UnknownLengthPieceStorage::getMissingPiece
|
|||
if(index == 0) {
|
||||
return getMissingPiece(0, 0, 0, cuid);
|
||||
} else {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ std::shared_ptr<Piece> UnknownLengthPieceStorage::getPiece(size_t index)
|
|||
return piece_;
|
||||
}
|
||||
} else {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -532,12 +532,12 @@ createMetadataInfoFromFirstFileEntry
|
|||
const std::shared_ptr<DownloadContext>& dctx)
|
||||
{
|
||||
if(dctx->getFileEntries().empty()) {
|
||||
return std::shared_ptr<MetadataInfo>();
|
||||
return nullptr;
|
||||
} else {
|
||||
std::vector<std::string> uris;
|
||||
dctx->getFileEntries()[0]->getUris(uris);
|
||||
if(uris.empty()) {
|
||||
return std::shared_ptr<MetadataInfo>();
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_shared<MetadataInfo>(gid, uris[0]);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
virtual std::shared_ptr<UDPTrackerRequest>
|
||||
createUDPTrackerRequest(const std::string& remoteAddr, uint16_t remotePort,
|
||||
uint16_t localPort) {
|
||||
return std::shared_ptr<UDPTrackerRequest>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void setAnnounceUrl(const std::string& url) {
|
||||
|
|
|
@ -13,18 +13,18 @@ public:
|
|||
createPingTask(const std::shared_ptr<DHTNode>& remoteNode,
|
||||
int numRetry = 0)
|
||||
{
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<DHTTask>
|
||||
createNodeLookupTask(const unsigned char* targetID)
|
||||
{
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<DHTTask> createBucketRefreshTask()
|
||||
{
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<DHTTask>
|
||||
|
@ -32,20 +32,20 @@ public:
|
|||
uint16_t tcpPort,
|
||||
const std::shared_ptr<PeerStorage>& peerStorage)
|
||||
{
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<DHTTask>
|
||||
createPeerAnnounceTask(const unsigned char* infoHash)
|
||||
{
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<DHTTask>
|
||||
createReplaceNodeTask(const std::shared_ptr<DHTBucket>& bucket,
|
||||
const std::shared_ptr<DHTNode>& newNode)
|
||||
{
|
||||
return std::shared_ptr<DHTTask>();
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
|
||||
virtual std::shared_ptr<Peer> checkoutPeer(cuid_t cuid)
|
||||
{
|
||||
return std::shared_ptr<Peer>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual void returnPeer(const std::shared_ptr<Peer>& peer)
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
cuid_t cuid)
|
||||
{
|
||||
if(missingIndexes.empty()) {
|
||||
return std::shared_ptr<Piece>();
|
||||
return nullptr;
|
||||
} else {
|
||||
size_t index = missingIndexes.front();
|
||||
missingIndexes.pop_front();
|
||||
|
|
Loading…
Reference in New Issue