diff options
author | Brad King <brad.king@kitware.com> | 2021-05-14 18:58:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-05-17 14:02:16 (GMT) |
commit | ea9b1d36b8cdf384903021d41ca665848895480f (patch) | |
tree | 752d8b9583e673cdde2106d2df59c96b06961bff /Source/cmStateDirectory.cxx | |
parent | 2d9109df7cae62138d7d0347f4e90330d053424b (diff) | |
download | CMake-ea9b1d36b8cdf384903021d41ca665848895480f.zip CMake-ea9b1d36b8cdf384903021d41ca665848895480f.tar.gz CMake-ea9b1d36b8cdf384903021d41ca665848895480f.tar.bz2 |
cmStateDirectory: Clarify relative path top selection logic
Re-implement the same algorithm using direct iteration without
collecting a vector first.
Diffstat (limited to 'Source/cmStateDirectory.cxx')
-rw-r--r-- | Source/cmStateDirectory.cxx | 56 |
1 files changed, 18 insertions, 38 deletions
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 31ee458..140ff0d 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -26,57 +26,37 @@ static std::string const kSUBDIRECTORIES = "SUBDIRECTORIES"; void cmStateDirectory::ComputeRelativePathTopSource() { - cmStateSnapshot snapshot = this->Snapshot_; - std::vector<cmStateSnapshot> snapshots; - snapshots.push_back(snapshot); - while (true) { - snapshot = snapshot.GetBuildsystemDirectoryParent(); - if (snapshot.IsValid()) { - snapshots.push_back(snapshot); - } else { - break; - } - } - - std::string result = snapshots.front().GetDirectory().GetCurrentSource(); - // Walk up the buildsystem directory tree to find the highest source // directory that contains the current source directory. - for (cmStateSnapshot const& snp : cmMakeRange(snapshots).advance(1)) { - std::string currentSource = snp.GetDirectory().GetCurrentSource(); - if (cmSystemTools::IsSubDirectory(result, currentSource)) { - result = currentSource; + cmStateSnapshot snapshot = this->Snapshot_; + for (cmStateSnapshot parent = snapshot.GetBuildsystemDirectoryParent(); + parent.IsValid(); parent = parent.GetBuildsystemDirectoryParent()) { + if (cmSystemTools::IsSubDirectory( + snapshot.GetDirectory().GetCurrentSource(), + parent.GetDirectory().GetCurrentSource())) { + snapshot = parent; } } - this->DirectoryState->RelativePathTopSource = result; + this->DirectoryState->RelativePathTopSource = + snapshot.GetDirectory().GetCurrentSource(); } void cmStateDirectory::ComputeRelativePathTopBinary() { - cmStateSnapshot snapshot = this->Snapshot_; - std::vector<cmStateSnapshot> snapshots; - snapshots.push_back(snapshot); - while (true) { - snapshot = snapshot.GetBuildsystemDirectoryParent(); - if (snapshot.IsValid()) { - snapshots.push_back(snapshot); - } else { - break; - } - } - - std::string result = snapshots.front().GetDirectory().GetCurrentBinary(); - // Walk up the buildsystem directory tree to find the highest binary // directory that contains the current binary directory. - for (cmStateSnapshot const& snp : cmMakeRange(snapshots).advance(1)) { - std::string currentBinary = snp.GetDirectory().GetCurrentBinary(); - if (cmSystemTools::IsSubDirectory(result, currentBinary)) { - result = currentBinary; + cmStateSnapshot snapshot = this->Snapshot_; + for (cmStateSnapshot parent = snapshot.GetBuildsystemDirectoryParent(); + parent.IsValid(); parent = parent.GetBuildsystemDirectoryParent()) { + if (cmSystemTools::IsSubDirectory( + snapshot.GetDirectory().GetCurrentBinary(), + parent.GetDirectory().GetCurrentBinary())) { + snapshot = parent; } } - this->DirectoryState->RelativePathTopBinary = result; + this->DirectoryState->RelativePathTopBinary = + snapshot.GetDirectory().GetCurrentBinary(); } std::string const& cmStateDirectory::GetCurrentSource() const |