more use of nullptr, minor refactor and formatting (#1267)

This commit is contained in:
Alden Torres 2016-10-28 12:28:27 -04:00 committed by Arvid Norberg
parent cb5d116fb9
commit dac0b9ec64
6 changed files with 35 additions and 35 deletions

View File

@ -441,7 +441,7 @@ namespace libtorrent
// pick the least recently used ones first
// return the number of blocks that was requested to be evicted
// that couldn't be
int try_evict_blocks(int num, cached_piece_entry* ignore = 0);
int try_evict_blocks(int num, cached_piece_entry* ignore = nullptr);
// try to evict a single volatile piece, if there is one.
void try_evict_one_volatile();

View File

@ -40,7 +40,7 @@ namespace libtorrent
template <typename T>
struct list_node
{
list_node() : prev(0), next(0) {}
list_node() : prev(nullptr), next(nullptr) {}
T* prev;
T* next;
};
@ -48,7 +48,7 @@ namespace libtorrent
template <typename T>
struct list_iterator
{
template <typename U>
template <typename U, typename Cond>
friend struct linked_list;
T const* get() const { return m_current; }
@ -63,9 +63,8 @@ namespace libtorrent
T* m_current;
};
// T must derive from list_node<T>. Having an enable_if here would require T
// to be a complete type, which is a bit too restrictive.
template <typename T>
template <typename T, typename Cond = typename std::enable_if<
std::is_base_of<list_node<T>, T>::value>::type>
struct linked_list
{
linked_list(): m_first(nullptr), m_last(nullptr), m_size(0) {}
@ -91,28 +90,28 @@ namespace libtorrent
#endif
if (e == m_first)
{
TORRENT_ASSERT(e->prev == 0);
TORRENT_ASSERT(e->prev == nullptr);
m_first = e->next;
}
if (e == m_last)
{
TORRENT_ASSERT(e->next == 0);
TORRENT_ASSERT(e->next == nullptr);
m_last = e->prev;
}
if (e->prev) e->prev->next = e->next;
if (e->next) e->next->prev = e->prev;
e->next = 0;
e->prev = 0;
e->next = nullptr;
e->prev = nullptr;
TORRENT_ASSERT(m_size > 0);
--m_size;
TORRENT_ASSERT(m_last == 0 || m_last->next == 0);
TORRENT_ASSERT(m_last == nullptr || m_last->next == nullptr);
}
void push_front(T* e)
{
TORRENT_ASSERT(e->next == 0);
TORRENT_ASSERT(e->prev== 0);
TORRENT_ASSERT(m_last == 0 || m_last->next == 0);
e->prev = 0;
TORRENT_ASSERT(e->next == nullptr);
TORRENT_ASSERT(e->prev== nullptr);
TORRENT_ASSERT(m_last == nullptr || m_last->next == nullptr);
e->prev = nullptr;
e->next = m_first;
if (m_first) m_first->prev = e;
else m_last = e;
@ -121,11 +120,11 @@ namespace libtorrent
}
void push_back(T* e)
{
TORRENT_ASSERT(e->next == 0);
TORRENT_ASSERT(e->prev== 0);
TORRENT_ASSERT(m_last == 0 || m_last->next == 0);
TORRENT_ASSERT(e->next == nullptr);
TORRENT_ASSERT(e->prev== nullptr);
TORRENT_ASSERT(m_last == nullptr || m_last->next == nullptr);
e->prev = m_last;
e->next = 0;
e->next = nullptr;
if (m_last) m_last->next = e;
else m_first = e;
m_last = e;
@ -133,11 +132,11 @@ namespace libtorrent
}
T* get_all()
{
TORRENT_ASSERT(m_last == 0 || m_last->next == 0);
TORRENT_ASSERT(m_first == 0 || m_first->prev == 0);
TORRENT_ASSERT(m_last == nullptr || m_last->next == nullptr);
TORRENT_ASSERT(m_first == nullptr || m_first->prev == nullptr);
T* e = m_first;
m_first = 0;
m_last = 0;
m_first = nullptr;
m_last = nullptr;
m_size = 0;
return e;
}
@ -155,4 +154,3 @@ namespace libtorrent
}
#endif // LINKED_LIST_HPP

View File

@ -770,7 +770,7 @@ namespace libtorrent
//
// The optional second argument ``options`` can be used to delete all the
// files downloaded by this torrent. To do so, pass in the value
// ``session::delete_files``. The removal of the torrent is asynchronous,
// ``session_handle::delete_files``. The removal of the torrent is asynchronous,
// there is no guarantee that adding the same torrent immediately after
// it was removed will not throw a system_error exception. Once
// the torrent is deleted, a torrent_deleted_alert is posted.

View File

@ -609,7 +609,7 @@ void block_cache::try_evict_one_volatile()
}
}
cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, int cache_state)
cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, int const cache_state)
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;

View File

@ -339,7 +339,7 @@ namespace libtorrent
// count number of blocks that would be flushed
int num_blocks = 0;
for (int i = end-1; i >= 0; --i)
for (int i = end - 1; i >= 0; --i)
num_blocks += (p->blocks[i].dirty && !p->blocks[i].pending);
// we did not satisfy the block_limit requirement
@ -1267,13 +1267,13 @@ namespace libtorrent
}
// this is the offset that's aligned to block boundaries
std::int64_t const adjusted_offset = j->d.io.offset & ~(block_size-1);
std::int64_t const adjusted_offset = j->d.io.offset & ~(block_size - 1);
// if this is the last piece, adjust the size of the
// last buffer to match up
iov[iov_len-1].iov_len = (std::min)(int(piece_size - adjusted_offset)
- (iov_len-1) * block_size, block_size);
TORRENT_ASSERT(iov[iov_len-1].iov_len > 0);
iov[iov_len - 1].iov_len = (std::min)(int(piece_size - adjusted_offset)
- (iov_len - 1) * block_size, block_size);
TORRENT_ASSERT(iov[iov_len - 1].iov_len > 0);
// at this point, all the buffers are allocated and iov is initialized
// and the blocks have their refcounters incremented, so no other thread
@ -1643,7 +1643,7 @@ namespace libtorrent
void disk_io_thread::async_write(piece_manager* storage, peer_request const& r
, disk_buffer_holder buffer
, std::function<void(disk_io_job const*)> handler
, int flags)
, int const flags)
{
INVARIANT_CHECK;
@ -1760,7 +1760,7 @@ namespace libtorrent
// first check to see if the hashing is already done
std::unique_lock<std::mutex> l(m_cache_mutex);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe && !pe->hashing && pe->hash && pe->hash->offset == piece_size)
if (pe != nullptr && !pe->hashing && pe->hash && pe->hash->offset == piece_size)
{
sha1_hash result = pe->hash->h.final();
std::memcpy(j->d.piece_hash, result.data(), 20);
@ -1889,7 +1889,7 @@ namespace libtorrent
disk_io_job* qj = m_hash_io_jobs.m_queued_jobs.get_all();
jobqueue_t to_abort;
while (qj)
while (qj != nullptr)
{
disk_io_job* next = qj->next;
#if TORRENT_USE_ASSERTS
@ -2225,7 +2225,7 @@ namespace libtorrent
std::unique_lock<std::mutex> l(m_cache_mutex);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe)
if (pe != nullptr)
{
TORRENT_ASSERT(pe->in_use);
#if TORRENT_USE_ASSERTS

View File

@ -155,6 +155,7 @@ namespace libtorrent
namespace {
#if TORRENT_USE_ASSERTS
int count_bufs(span<file::iovec_t const> bufs, int bytes)
{
int size = 0;
@ -166,6 +167,7 @@ namespace libtorrent
if (size >= bytes) return count;
}
}
#endif
#ifdef TORRENT_DISK_STATS
static std::atomic<int> event_id;