java-topology/defects/cmake/patch/cmake-0002-getdirectories-unordered-map.patch

31 lines
1.4 KiB
Diff

# UNDF: UNDF-2026-000000033
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index abc1234..def5678 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -456,14 +456,19 @@ std::vector<BT<std::string>>
cmComputeLinkInformation::GetDirectoriesWithBacktraces()
{
std::vector<BT<std::string>> directoriesWithBacktraces;
std::vector<BT<std::string>> targetLinkDirectories =
this->Target->GetLinkDirectories(this->Config, this->LinkLanguage);
+ // Build an index from directory string → BT entry for O(1) lookup.
+ std::unordered_map<std::string, BT<std::string>> dirIndex;
+ dirIndex.reserve(targetLinkDirectories.size());
+ for (auto& bt : targetLinkDirectories)
+ dirIndex.emplace(bt.Value, std::move(bt));
+
std::vector<std::string> const& orderedDirectories = this->GetDirectories();
for (std::string const& dir : orderedDirectories) {
- auto result = std::find(targetLinkDirectories.begin(),
- targetLinkDirectories.end(), dir);
- if (result != targetLinkDirectories.end()) {
- directoriesWithBacktraces.emplace_back(std::move(*result));
+ auto result = dirIndex.find(dir);
+ if (result != dirIndex.end()) {
+ directoriesWithBacktraces.emplace_back(std::move(result->second));
} else {
directoriesWithBacktraces.emplace_back(dir);
}