logic: PARSING files are UNPARSED
* changed ***FileIsUnparsed in FileRegister to disregard files that are currently parsing. * made Cach more generic by adding the option of providing a custom hasher
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
#define CACHE_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
template <typename KeyType, typename ValType>
|
||||
template <typename KeyType, typename ValType, typename Hasher = std::hash<KeyType>>
|
||||
class Cache
|
||||
{
|
||||
public:
|
||||
@@ -13,19 +13,19 @@ public:
|
||||
|
||||
private:
|
||||
std::function<ValType(KeyType)> m_calculator;
|
||||
std::map<KeyType, ValType> m_map;
|
||||
std::unordered_map<KeyType, ValType, Hasher> m_map;
|
||||
};
|
||||
|
||||
template <typename KeyType, typename ValType>
|
||||
Cache<KeyType, ValType>::Cache(std::function<ValType(KeyType)> calculator)
|
||||
template <typename KeyType, typename ValType, typename Hasher>
|
||||
Cache<KeyType, ValType, Hasher>::Cache(std::function<ValType(KeyType)> calculator)
|
||||
: m_calculator(calculator)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename KeyType, typename ValType>
|
||||
ValType Cache<KeyType, ValType>::getValue(KeyType key)
|
||||
template <typename KeyType, typename ValType, typename Hasher = hash<KeyType>>
|
||||
ValType Cache<KeyType, ValType, Hasher>::getValue(KeyType key)
|
||||
{
|
||||
typename std::map<KeyType, ValType>::const_iterator it = m_map.find(key);
|
||||
typename std::unordered_map<KeyType, ValType>::const_iterator it = m_map.find(key);
|
||||
if (it != m_map.end())
|
||||
{
|
||||
return it->second;
|
||||
|
||||
@@ -107,28 +107,12 @@ bool FileRegister::sourceFileIsParsed(const FilePath& filePath) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (it->second == STATE_UNPARSED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (it->second == STATE_PARSED)
|
||||
if (it->second == STATE_PARSED)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadFileMutex);
|
||||
|
||||
std::map<std::thread::id, std::set<FilePath>>::const_iterator it2 = m_threadParsingFiles.find(std::this_thread::get_id());
|
||||
if (it2 != m_threadParsingFiles.end())
|
||||
{
|
||||
if (it2->second.find(filePath) != it2->second.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,28 +127,12 @@ bool FileRegister::includeFileIsParsed(const FilePath& filePath) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (it->second == STATE_UNPARSED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (it->second == STATE_PARSED)
|
||||
if (it->second == STATE_PARSED)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadFileMutex);
|
||||
|
||||
std::map<std::thread::id, std::set<FilePath>>::const_iterator it2 = m_threadParsingFiles.find(std::this_thread::get_id());
|
||||
if (it2 != m_threadParsingFiles.end())
|
||||
{
|
||||
if (it2->second.find(filePath) != it2->second.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user