diff options
author | Brad King <brad.king@kitware.com> | 2022-01-26 13:02:12 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-01-26 13:02:23 (GMT) |
commit | a600b9207ec71921a6398b785b03d909713d396f (patch) | |
tree | f916faf8600cb62f8231e58687298624ad497746 | |
parent | c4acdcbc1cf99b0332c0842e0499fa5067b3debb (diff) | |
parent | 6f835c3699f136d66f8f4baacf2b95589cf32257 (diff) | |
download | CMake-a600b9207ec71921a6398b785b03d909713d396f.zip CMake-a600b9207ec71921a6398b785b03d909713d396f.tar.gz CMake-a600b9207ec71921a6398b785b03d909713d396f.tar.bz2 |
Merge topic 'cache-short-paths'
6f835c3699 cmOutputConverter: Cache Short Paths
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6887
-rw-r--r-- | Source/cmOutputConverter.cxx | 30 |
1 files changed, 26 insertions, 4 deletions
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::MaybeRelativeToCurBinDir( 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); |