From a241fd13025422d7a0fae95a0d4cbb2e568f5b0f Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Tue, 6 Mar 2018 12:19:57 -0500
Subject: [PATCH] SystemTools: Remove caching from public GetActualCaseForPath

Do not expose caching to `GetActualCaseForPath` callers.  Cache path
case conversion results internally for `CollapseFullPath` only.
---
 SystemTools.cxx    | 11 +++++++++--
 SystemTools.hxx.in |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/SystemTools.cxx b/SystemTools.cxx
index 3e91a075..106afe50 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3253,7 +3253,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
 
   SystemTools::CheckTranslationPath(newPath);
 #ifdef _WIN32
-  newPath = SystemTools::GetActualCaseForPath(newPath);
+  newPath = SystemTools::GetActualCaseForPathCached(newPath);
   SystemTools::ConvertToUnixSlashes(newPath);
 #endif
   // Return the reconstructed path.
@@ -3411,6 +3411,13 @@ std::string SystemTools::GetActualCaseForPath(const std::string& p)
 #ifndef _WIN32
   return p;
 #else
+  return GetCasePathName(p);
+#endif
+}
+
+#ifdef _WIN32
+std::string SystemTools::GetActualCaseForPathCached(std::string const& p)
+{
   // Check to see if actual case has already been called
   // for this path, and the result is stored in the PathCaseMap
   SystemToolsPathCaseMap::iterator i = SystemTools::PathCaseMap->find(p);
@@ -3423,8 +3430,8 @@ std::string SystemTools::GetActualCaseForPath(const std::string& p)
   }
   (*SystemTools::PathCaseMap)[p] = casePath;
   return casePath;
-#endif
 }
+#endif
 
 const char* SystemTools::SplitPathRootComponent(const std::string& p,
                                                 std::string* root)
diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in
index 719d45c0..e79e3fcf 100644
--- a/SystemTools.hxx.in
+++ b/SystemTools.hxx.in
@@ -988,6 +988,7 @@ private:
    */
   static SystemToolsTranslationMap* TranslationMap;
 #ifdef _WIN32
+  static std::string GetActualCaseForPathCached(std::string const& path);
   static SystemToolsPathCaseMap* PathCaseMap;
   static SystemToolsEnvMap* EnvMap;
 #endif
-- 
GitLab