Merge topic 'parser-cleanup'

4959276c02 cmListFileCache: Remove cmCommandContext
0386641142 cmListFileCache: Rename FromCommandContext to FromListFileFunction
3c4fa4c892 cmListFileCache: Move cmListFileFunction earlier

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6899
diff --git a/Modules/FindMPI/test_mpi.c b/Modules/FindMPI/test_mpi.c
index 70d7e1d..36b5dfd 100644
--- a/Modules/FindMPI/test_mpi.c
+++ b/Modules/FindMPI/test_mpi.c
@@ -7,7 +7,7 @@
 #endif
 
 #if defined(MPI_VERSION) && defined(MPI_SUBVERSION)
-const static char mpiver_str[] = { 'I', 'N',
+static const char mpiver_str[] = { 'I', 'N',
                                    'F', 'O',
                                    ':', 'M',
                                    'P', 'I',
diff --git a/Modules/FindXercesC.cmake b/Modules/FindXercesC.cmake
index af1b0b4..d39bbf6 100644
--- a/Modules/FindXercesC.cmake
+++ b/Modules/FindXercesC.cmake
@@ -91,11 +91,13 @@
                NAMES "xerces-c"
                      "xerces-c_${XercesC_VERSION_MAJOR}"
                      "xerces-c-${XercesC_VERSION_MAJOR}.${XercesC_VERSION_MINOR}"
+               NAMES_PER_DIR
                DOC "Xerces-C++ libraries (release)")
   find_library(XercesC_LIBRARY_DEBUG
                NAMES "xerces-cd"
                      "xerces-c_${XercesC_VERSION_MAJOR}D"
                      "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D"
+               NAMES_PER_DIR
                DOC "Xerces-C++ libraries (debug)")
   include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
   select_library_configurations(XercesC)
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 2a580b4..a376a0f 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,7 +1,7 @@
 # CMake version number components.
 set(CMake_VERSION_MAJOR 3)
 set(CMake_VERSION_MINOR 22)
-set(CMake_VERSION_PATCH 20220125)
+set(CMake_VERSION_PATCH 20220126)
 #set(CMake_VERSION_RC 0)
 set(CMake_VERSION_IS_DIRTY 0)
 
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index 4503038..b143170 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -8,6 +8,11 @@
 #include <set>
 #include <vector>
 
+#ifdef _WIN32
+#  include <unordered_map>
+#  include <utility>
+#endif
+
 #include "cmState.h"
 #include "cmStateDirectory.h"
 #include "cmStringAlgorithms.h"
@@ -117,17 +122,34 @@
 std::string cmOutputConverter::ConvertToOutputForExisting(
   const std::string& remote, OutputFormat format) const
 {
+#ifdef _WIN32
+  // Cache the Short Paths since we only convert the same few paths anyway and
+  // calling `GetShortPathNameW` is really expensive.
+  static std::unordered_map<std::string, std::string> shortPathCache{};
+
   // If this is a windows shell, the result has a space, and the path
   // already exists, we can use a short-path to reference it without a
   // space.
   if (this->GetState()->UseWindowsShell() &&
       remote.find_first_of(" #") != std::string::npos &&
       cmSystemTools::FileExists(remote)) {
-    std::string tmp;
-    if (cmSystemTools::GetShortPath(remote, tmp)) {
-      return this->ConvertToOutputFormat(tmp, format);
-    }
+
+    std::string shortPath = [&]() {
+      auto cachedShortPathIt = shortPathCache.find(remote);
+
+      if (cachedShortPathIt != shortPathCache.end()) {
+        return cachedShortPathIt->second;
+      }
+
+      std::string tmp{};
+      cmSystemTools::GetShortPath(remote, tmp);
+      shortPathCache[remote] = tmp;
+      return tmp;
+    }();
+
+    return this->ConvertToOutputFormat(shortPath, format);
   }
+#endif
 
   // Otherwise, perform standard conversion.
   return this->ConvertToOutputFormat(remote, format);