From 31602583930b6c517c439ae8c15df26043031345 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 13 Mar 2019 19:03:35 +0100 Subject: 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. --- Source/cmFileTimeComparison.cxx | 61 ++++++++--------------------------------- Source/cmFileTimeComparison.h | 8 +++--- 2 files changed, 15 insertions(+), 54 deletions(-) diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx index 5022cab..2115029 100644 --- a/Source/cmFileTimeComparison.cxx +++ b/Source/cmFileTimeComparison.cxx @@ -6,72 +6,33 @@ #include #include -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 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; if (this->Load(f1, ft1) && this->Load(f2, 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; diff --git a/Source/cmFileTimeComparison.h b/Source/cmFileTimeComparison.h index cc321f0..80ea409 100644 --- a/Source/cmFileTimeComparison.h +++ b/Source/cmFileTimeComparison.h @@ -7,8 +7,7 @@ #include "cmFileTime.h" #include - -class cmFileTimeComparisonInternal; +#include /** \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 FileTimeMap; + FileTimeMap FileTimes; }; #endif -- cgit v0.12