Commit 31602583 authored by Sebastian Holtermann's avatar Sebastian Holtermann

cmFileTimeComparison: Replace anonymous private class with std::map

After the switch to `cmFileTime`, the anonymous private class of
`cmFileTimeComparison` held only a `std::map`.  This moves the
`std::map` to the `cmFileTimeComparison` class itself and removes the
instantiation of an anonymous private class.
parent 103aa9e4
......@@ -6,71 +6,32 @@
#include <unordered_map>
#include <utility>
class cmFileTimeComparisonInternal
{
public:
inline bool Load(std::string const& fname, cmFileTime& ftm);
inline bool FileTimeCompare(std::string const& f1, std::string const& f2,
int* result);
bool FileTimesDiffer(std::string const& f1, std::string const& f2);
cmFileTimeComparison::cmFileTimeComparison() = default;
private:
typedef std::unordered_map<std::string, cmFileTime> FileStatsMap;
FileStatsMap Files;
};
cmFileTimeComparison::~cmFileTimeComparison() = default;
bool cmFileTimeComparisonInternal::Load(std::string const& fname,
cmFileTime& ftm)
bool cmFileTimeComparison::Load(std::string const& fileName,
cmFileTime& fileTime)
{
// Use the stored time if available.
{
auto fit = this->Files.find(fname);
if (fit != this->Files.end()) {
ftm = fit->second;
auto fit = this->FileTimes.find(fileName);
if (fit != this->FileTimes.end()) {
fileTime = fit->second;
return true;
}
}
// Read file time from OS
if (!ftm.Load(fname)) {
if (!fileTime.Load(fileName)) {
return false;
}
// Store file time in cache
this->Files[fname] = ftm;
this->FileTimes[fileName] = fileTime;
return true;
}
cmFileTimeComparison::cmFileTimeComparison()
{
this->Internals = new cmFileTimeComparisonInternal;
}
cmFileTimeComparison::~cmFileTimeComparison()
{
delete this->Internals;
}
bool cmFileTimeComparison::Load(std::string const& fileName,
cmFileTime& fileTime)
{
return this->Internals->Load(fileName, fileTime);
}
bool cmFileTimeComparison::FileTimeCompare(std::string const& f1,
std::string const& f2, int* result)
{
return this->Internals->FileTimeCompare(f1, f2, result);
}
bool cmFileTimeComparison::FileTimesDiffer(std::string const& f1,
std::string const& f2)
{
return this->Internals->FileTimesDiffer(f1, f2);
}
bool cmFileTimeComparisonInternal::FileTimeCompare(std::string const& f1,
std::string const& f2,
int* result)
{
// Get the modification time for each file.
cmFileTime ft1, ft2;
......@@ -84,8 +45,8 @@ bool cmFileTimeComparisonInternal::FileTimeCompare(std::string const& f1,
return false;
}
bool cmFileTimeComparisonInternal::FileTimesDiffer(std::string const& f1,
std::string const& f2)
bool cmFileTimeComparison::FileTimesDiffer(std::string const& f1,
std::string const& f2)
{
// Get the modification time for each file.
cmFileTime ft1, ft2;
......
......@@ -7,8 +7,7 @@
#include "cmFileTime.h"
#include <string>
class cmFileTimeComparisonInternal;
#include <unordered_map>
/** \class cmFileTimeComparison
* \brief Caches file modification times in an internal map for fast lookups.
......@@ -45,8 +44,9 @@ public:
*/
bool FileTimesDiffer(std::string const& f1, std::string const& f2);
protected:
cmFileTimeComparisonInternal* Internals;
private:
typedef std::unordered_map<std::string, cmFileTime> FileTimeMap;
FileTimeMap FileTimes;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment