diff --git a/src/lib/data/indexer/IndexerCommandList.cpp b/src/lib/data/indexer/IndexerCommandList.cpp index a66984b3..bf8a2d8c 100644 --- a/src/lib/data/indexer/IndexerCommandList.cpp +++ b/src/lib/data/indexer/IndexerCommandList.cpp @@ -1,7 +1,6 @@ #include "data/indexer/IndexerCommandList.h" #include -#include #include "utility/file/FileSystem.h" #include "utility/logging/logging.h" @@ -26,7 +25,7 @@ size_t IndexerCommandList::size() const return m_commands.size(); } -void IndexerCommandList::shuffle() +void IndexerCommandList::sort() { std::lock_guard lock(m_commandsMutex); @@ -48,9 +47,16 @@ void IndexerCommandList::shuffle() if (sourceFileSizesToCommands.size() > 2) { - srand(unsigned(time(NULL))); - std::random_shuffle(sourceFileSizesToCommands.begin(), sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2); - std::random_shuffle(sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2, sourceFileSizesToCommands.end()); + std::sort( + sourceFileSizesToCommands.begin(), + sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2, + [](const PairType& p, const PairType& q) { return p.second->getSourceFilePath().wstr() < q.second->getSourceFilePath().wstr(); } + ); + std::sort( + sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2, + sourceFileSizesToCommands.end(), + [](const PairType& p, const PairType& q) { return p.second->getSourceFilePath().wstr() < q.second->getSourceFilePath().wstr(); } + ); } m_commands.clear(); diff --git a/src/lib/data/indexer/IndexerCommandList.h b/src/lib/data/indexer/IndexerCommandList.h index a4055f30..74376157 100644 --- a/src/lib/data/indexer/IndexerCommandList.h +++ b/src/lib/data/indexer/IndexerCommandList.h @@ -14,7 +14,7 @@ public: size_t size() const; - void shuffle(); + void sort(); std::shared_ptr consumeCommand(); diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 307a25a8..8d8e5464 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -468,7 +468,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di indexerThreadCount = std::min(indexerThreadCount, indexerCommandList->size()); if (indexerThreadCount > 1) { - indexerCommandList->shuffle(); + indexerCommandList->sort(); } std::shared_ptr storageProvider = std::make_shared();