summaryrefslogtreecommitdiffstats
path: root/Source/cmComputeLinkDepends.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-09-06 17:10:55 (GMT)
committerBrad King <brad.king@kitware.com>2018-09-07 12:57:51 (GMT)
commitfc7e4d1ed85370d03acbd62bc753cced3550752b (patch)
tree25e5d5719b2da65398e7d2f0fbc4cb490e4428ff /Source/cmComputeLinkDepends.cxx
parentf782759ed0997eb3d71e1187a829da62668ed5d2 (diff)
downloadCMake-fc7e4d1ed85370d03acbd62bc753cced3550752b.zip
CMake-fc7e4d1ed85370d03acbd62bc753cced3550752b.tar.gz
CMake-fc7e4d1ed85370d03acbd62bc753cced3550752b.tar.bz2
cmLinkItem: Convert to a "sum type" over a string and target pointer
Avoid exposing the item name implicitly as std::string. When the item is a target, avoid storing a second copy of its name. Most link item construction is paired with calls to `FindTargetToLink` to get the possible target pointer. Rename these methods to `ResolveLinkItem` and refactor them to construct the entire item.
Diffstat (limited to 'Source/cmComputeLinkDepends.cxx')
-rw-r--r--Source/cmComputeLinkDepends.cxx30
1 files changed, 16 insertions, 14 deletions
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index b1f3860..3659a1e 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -295,22 +295,24 @@ std::map<std::string, int>::iterator cmComputeLinkDepends::AllocateLinkEntry(
int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item)
{
// Check if the item entry has already been added.
- std::map<std::string, int>::iterator lei = this->LinkEntryIndex.find(item);
+ std::map<std::string, int>::iterator lei =
+ this->LinkEntryIndex.find(item.AsStr());
if (lei != this->LinkEntryIndex.end()) {
// Yes. We do not need to follow the item's dependencies again.
return lei->second;
}
// Allocate a spot for the item entry.
- lei = this->AllocateLinkEntry(item);
+ lei = this->AllocateLinkEntry(item.AsStr());
// Initialize the item entry.
int index = lei->second;
LinkEntry& entry = this->EntryList[index];
- entry.Item = item;
+ entry.Item = item.AsStr();
entry.Target = item.Target;
- entry.IsFlag = (!entry.Target && item[0] == '-' && item[1] != 'l' &&
- item.substr(0, 10) != "-framework");
+ entry.IsFlag =
+ (!entry.Target && entry.Item[0] == '-' && entry.Item[1] != 'l' &&
+ entry.Item.substr(0, 10) != "-framework");
// If the item has dependencies queue it to follow them.
if (entry.Target) {
@@ -396,14 +398,14 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
{
// Check if the target already has an entry.
std::map<std::string, int>::iterator lei =
- this->LinkEntryIndex.find(dep.Item);
+ this->LinkEntryIndex.find(dep.Item.AsStr());
if (lei == this->LinkEntryIndex.end()) {
// Allocate a spot for the item entry.
- lei = this->AllocateLinkEntry(dep.Item);
+ lei = this->AllocateLinkEntry(dep.Item.AsStr());
// Initialize the item entry.
LinkEntry& entry = this->EntryList[lei->second];
- entry.Item = dep.Item;
+ entry.Item = dep.Item.AsStr();
entry.Target = dep.Item.Target;
// This item was added specifically because it is a dependent
@@ -473,9 +475,9 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
// If the library is meant for this link type then use it.
if (llt == GENERAL_LibraryType || llt == this->LinkType) {
- actual_libs.emplace_back(d, this->FindTargetToLink(depender_index, d));
+ actual_libs.emplace_back(this->ResolveLinkItem(depender_index, d));
} else if (this->OldLinkDirMode) {
- cmLinkItem item(d, this->FindTargetToLink(depender_index, d));
+ cmLinkItem item = this->ResolveLinkItem(depender_index, d);
this->CheckWrongConfigItem(item);
}
@@ -512,7 +514,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
// Skip entries that will resolve to the target getting linked or
// are empty.
cmLinkItem const& item = l;
- if (item == this->Target->GetName() || item.empty()) {
+ if (item.AsStr() == this->Target->GetName() || item.AsStr().empty()) {
continue;
}
@@ -553,8 +555,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
}
}
-cmGeneratorTarget const* cmComputeLinkDepends::FindTargetToLink(
- int depender_index, const std::string& name)
+cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index,
+ const std::string& name)
{
// Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target;
@@ -564,7 +566,7 @@ cmGeneratorTarget const* cmComputeLinkDepends::FindTargetToLink(
from = depender;
}
}
- return from->FindTargetToLink(name);
+ return from->ResolveLinkItem(name);
}
void cmComputeLinkDepends::InferDependencies()