From 71cf6bb5f4bf6a97ec410d1a2b06fb619a5c8a98 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 30 May 2016 12:21:39 +0200 Subject: [PATCH] logic: randomize source file parsing order to reduce header file double parsing saves 20% parsing time for Coati --- src/lib/utility/file/FileRegister.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib/utility/file/FileRegister.cpp b/src/lib/utility/file/FileRegister.cpp index 4cb24428..d679b10f 100644 --- a/src/lib/utility/file/FileRegister.cpp +++ b/src/lib/utility/file/FileRegister.cpp @@ -138,18 +138,16 @@ bool FileRegister::includeFileIsParsed(const FilePath& filePath) const FilePath FileRegister::consumeSourceFile() { + std::vector paths = getUnparsedSourceFilePaths(); + FilePath path; + + if (paths.size()) { + path = paths[rand() % paths.size()]; + std::lock_guard lock(m_sourceFileMutex); - for (std::map::iterator it = m_sourceFilePaths.begin(); it != m_sourceFilePaths.end(); it++) - { - if (it->second == STATE_UNPARSED) - { - it->second = STATE_PARSING; - path = it->first; - break; - } - } + m_sourceFilePaths[path] = STATE_PARSING; } if (!path.empty())