utility: Fixed bad performance of FilePath comparison

This commit is contained in:
Eberhard Graether
2015-04-23 22:31:51 +02:00
parent 3c7c3da527
commit ee8d35f084
2 changed files with 18 additions and 5 deletions
+15 -5
View File
@@ -2,22 +2,28 @@
FilePath::FilePath(const char* filePath)
: m_path(filePath)
, m_exists(false)
{
init();
}
FilePath::FilePath(const std::string& filePath)
: m_path(filePath)
, m_exists(false)
{
init();
}
FilePath::FilePath(const boost::filesystem::path& filePath)
: m_path(filePath)
, m_exists(false)
{
init();
}
bool FilePath::exists() const
{
return boost::filesystem::exists(m_path);
return m_exists;
}
std::string FilePath::str() const
@@ -75,10 +81,14 @@ bool FilePath::operator!=(const FilePath& other) const
bool FilePath::operator<(const FilePath& other) const
{
if (exists() && other.exists())
return m_path.compare(other.m_path) < 0;
}
void FilePath::init()
{
if (boost::filesystem::exists(m_path))
{
return boost::filesystem::canonical(m_path).compare(boost::filesystem::canonical(other.m_path)) < 0;
m_exists = true;
m_path = boost::filesystem::canonical(m_path);
}
return boost::filesystem::absolute(m_path).compare(boost::filesystem::absolute(other.m_path)) < 0;
}