Use Cache class
MODIFY
include/vcpkg/vcpkgpaths.h
include/vcpkg/vcpkgpaths.h
#include <vcpkg/binaryparagraph.h>
#include <vcpkg/packagespec.h>
+#include <vcpkg/base/cache.h>
#include <vcpkg/base/expected.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/lazy.h>
@@ -89,7 +90,7 @@ namespace vcpkg
private:
Lazy<std::vector<std::string>> available_triplets;
- mutable std::map<std::string, fs::path> tool_paths;
+ Cache<std::string, fs::path> tool_paths;
Lazy<std::vector<Toolset>> toolsets;
Lazy<std::vector<Toolset>> toolsets_vs2013;

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -91,14 +91,7 @@ namespace vcpkg
const fs::path& VcpkgPaths::get_tool_exe(const std::string& tool) const
{
- const auto it = this->tool_paths.find(tool);
- if (it != this->tool_paths.cend())
- {
- return it->second;
- }
-
- this->tool_paths[tool] = Commands::Fetch::get_tool_path(*this, tool);
- return this->tool_paths[tool];
+ return this->tool_paths.get_lazy(tool, [&]() { return Commands::Fetch::get_tool_path(*this, tool); });
}
const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const

Use Cache class