diff options
Diffstat (limited to 'src/checkqueue.h')
-rw-r--r-- | src/checkqueue.h | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/checkqueue.h b/src/checkqueue.h index d83f717fb7..2c21e5f7d0 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -11,6 +11,7 @@ #include <util/threadnames.h> #include <algorithm> +#include <iterator> #include <vector> template <typename T> @@ -111,13 +112,9 @@ private: // * Try to account for idle jobs which will instantly start helping. // * Don't do batches smaller than 1 (duh), or larger than nBatchSize. nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1))); - vChecks.resize(nNow); - for (unsigned int i = 0; i < nNow; i++) { - // We want the lock on the m_mutex to be as short as possible, so swap jobs from the global - // queue to the local batch vector instead of copying. - vChecks[i].swap(queue.back()); - queue.pop_back(); - } + auto start_it = queue.end() - nNow; + vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end())); + queue.erase(start_it, queue.end()); // Check whether we need to do work at all fOk = fAllOk; } @@ -165,7 +162,7 @@ public: } //! Add a batch of checks to the queue - void Add(std::vector<T>& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) + void Add(std::vector<T>&& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) { if (vChecks.empty()) { return; @@ -173,10 +170,7 @@ public: { LOCK(m_mutex); - for (T& check : vChecks) { - queue.emplace_back(); - check.swap(queue.back()); - } + queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end())); nTodo += vChecks.size(); } @@ -239,10 +233,11 @@ public: return fRet; } - void Add(std::vector<T>& vChecks) + void Add(std::vector<T>&& vChecks) { - if (pqueue != nullptr) - pqueue->Add(vChecks); + if (pqueue != nullptr) { + pqueue->Add(std::move(vChecks)); + } } ~CCheckQueueControl() |