diff --git a/src/dedup.cpp b/src/dedup.cpp index 1abad9c..653051c 100644 --- a/src/dedup.cpp +++ b/src/dedup.cpp @@ -50,7 +50,7 @@ void Dedup::start() { removeUninterestingFiles(foundfiles); // hashing - uint64_t bytesToHash = std::accumulate(foundfiles.begin(), foundfiles.end(), 0ul, [](uint64_t& c, const std::pair>& it) { return c + it.second->filesize; }); + uint64_t bytesToHash = std::accumulate(foundfiles.begin(), foundfiles.end(), 0ul, [](uint64_t& c, auto it) { return c + it.second->filesize; }); Log::info << foundfiles.size() << " files and " << FileSize(bytesToHash) << " are going to be hashed"; @@ -92,34 +92,38 @@ std::map Dedup::hash(std::multimap threads; - std::vector>::iterator> threadit; + std::vector>::iterator> threadends; + std::vector>::iterator> threadits; threads.reserve(HASHTHREADCOUNT); - threadit.reserve(HASHTHREADCOUNT + 1); + threadends.resize(HASHTHREADCOUNT); + threadits.resize(HASHTHREADCOUNT); // create threads Log::info << "spawning " << (int) HASHTHREADCOUNT << " hashing threads"; - threadit.push_back(foundfiles.begin()); - for(uint_fast8_t i = 0; i < HASHTHREADCOUNT; ++i) { + threadits.at(0) = foundfiles.begin(); + for(uint_fast8_t i = 1; i < HASHTHREADCOUNT; ++i) { // make a copy! - std::multimap>::iterator it = threadit.at(i); + std::multimap>::iterator it = threadits.at(i-1); std::advance(it, stepsize); - threadit.push_back(it); + + threadits.at(i) = it; + threadends.at(i-1) = it; } // make sure the last one is realy the last - threadit.at(HASHTHREADCOUNT) = foundfiles.end(); + threadends.at(HASHTHREADCOUNT-1) = foundfiles.end(); for(uint_fast8_t i = 0; i < HASHTHREADCOUNT; ++i) { - std::multimap>::iterator* itptr = &(threadit.at(i)); - std::multimap>::iterator* endptr = &(threadit.at(i+1)); + std::multimap>::iterator* itptr = &(threadits.at(i)); + const std::multimap>::iterator* endptr = &(threadends.at(i)); threads.push_back(new HasherThread( globalData, - [itptr, endptr]() -> std::shared_ptr { + [itptr, endptr, i]() -> std::shared_ptr { if(*itptr != *endptr) { - auto copy = *itptr; + std::shared_ptr value = (*itptr)->second; ++(*itptr); - return copy->second; + return value; } return nullptr; },