diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2021-08-27 13:54:54 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-09-03 13:52:14 (GMT) |
commit | ab94c369c9f653d249e5a48ccc43f2dd2d95bc56 (patch) | |
tree | 14421b0b0fb0f0b2461a2e73b73d8828da3e0d2b /Source/cmStateDirectory.cxx | |
parent | 80e0245e0e05c27dee316a9b53e23a4c0b12a9fe (diff) | |
download | CMake-ab94c369c9f653d249e5a48ccc43f2dd2d95bc56.zip CMake-ab94c369c9f653d249e5a48ccc43f2dd2d95bc56.tar.gz CMake-ab94c369c9f653d249e5a48ccc43f2dd2d95bc56.tar.bz2 |
Refactor: Convert parallel string/backtrace vectors to BT vectors
Diffstat (limited to 'Source/cmStateDirectory.cxx')
-rw-r--r-- | Source/cmStateDirectory.cxx | 186 |
1 files changed, 47 insertions, 139 deletions
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index ed5b5d8..8f83b02 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -19,6 +19,7 @@ #include "cmState.h" #include "cmStatePrivate.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" static std::string const kBINARY_DIR = "BINARY_DIR"; @@ -63,7 +64,7 @@ cmStateDirectory::cmStateDirectory( } template <typename T, typename U> -cmStringRange GetPropertyContent(T const& content, U contentEndPosition) +cmBTStringRange GetPropertyContent(T const& content, U contentEndPosition) { auto end = content.begin() + contentEndPosition; @@ -73,88 +74,59 @@ cmStringRange GetPropertyContent(T const& content, U contentEndPosition) return cmMakeRange(rbegin.base(), end); } -template <typename T, typename U, typename V> -cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces, - V contentEndPosition) -{ - auto entryEnd = content.begin() + contentEndPosition; - - auto rbegin = cm::make_reverse_iterator(entryEnd); - rbegin = std::find(rbegin, content.rend(), cmPropertySentinal); - - auto it = backtraces.begin() + std::distance(content.begin(), rbegin.base()); - - auto end = backtraces.end(); - return cmMakeRange(it, end); -} - -template <typename T, typename U, typename V> -void AppendEntry(T& content, U& backtraces, V& endContentPosition, - const std::string& value, const cmListFileBacktrace& lfbt) +template <typename T, typename U> +void AppendEntry(T& content, U& endContentPosition, + const BT<std::string>& value) { - if (value.empty()) { + if (value.Value.empty()) { return; } assert(endContentPosition == content.size()); content.push_back(value); - backtraces.push_back(lfbt); endContentPosition = content.size(); } -template <typename T, typename U, typename V> -void SetContent(T& content, U& backtraces, V& endContentPosition, - const std::string& vec, const cmListFileBacktrace& lfbt) +template <typename T, typename U> +void SetContent(T& content, U& endContentPosition, const BT<std::string>& vec) { assert(endContentPosition == content.size()); content.resize(content.size() + 2); - backtraces.resize(backtraces.size() + 2); content.back() = vec; - backtraces.back() = lfbt; endContentPosition = content.size(); } -template <typename T, typename U, typename V> -void ClearContent(T& content, U& backtraces, V& endContentPosition) +template <typename T, typename U> +void ClearContent(T& content, U& endContentPosition) { assert(endContentPosition == content.size()); content.resize(content.size() + 1); - backtraces.resize(backtraces.size() + 1); endContentPosition = content.size(); } -cmStringRange cmStateDirectory::GetIncludeDirectoriesEntries() const +cmBTStringRange cmStateDirectory::GetIncludeDirectoriesEntries() const { return GetPropertyContent( this->DirectoryState->IncludeDirectories, this->Snapshot_.Position->IncludeDirectoryPosition); } -cmBacktraceRange cmStateDirectory::GetIncludeDirectoriesEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, - this->Snapshot_.Position->IncludeDirectoryPosition); -} - void cmStateDirectory::AppendIncludeDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) + const BT<std::string>& vec) { AppendEntry(this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, - this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt); + this->Snapshot_.Position->IncludeDirectoryPosition, vec); } void cmStateDirectory::PrependIncludeDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) + const BT<std::string>& vec) { auto entryEnd = this->DirectoryState->IncludeDirectories.begin() + this->Snapshot_.Position->IncludeDirectoryPosition; @@ -164,167 +136,111 @@ void cmStateDirectory::PrependIncludeDirectoriesEntry( rbegin = std::find(rbegin, rend, cmPropertySentinal); auto entryIt = rbegin.base(); - auto entryBegin = this->DirectoryState->IncludeDirectories.begin(); - - auto btIt = this->DirectoryState->IncludeDirectoryBacktraces.begin() + - std::distance(entryBegin, entryIt); this->DirectoryState->IncludeDirectories.insert(entryIt, vec); - this->DirectoryState->IncludeDirectoryBacktraces.insert(btIt, lfbt); this->Snapshot_.Position->IncludeDirectoryPosition = this->DirectoryState->IncludeDirectories.size(); } -void cmStateDirectory::SetIncludeDirectories(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetIncludeDirectories(const BT<std::string>& vec) { SetContent(this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, - this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt); + this->Snapshot_.Position->IncludeDirectoryPosition, vec); } void cmStateDirectory::ClearIncludeDirectories() { ClearContent(this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, this->Snapshot_.Position->IncludeDirectoryPosition); } -cmStringRange cmStateDirectory::GetCompileDefinitionsEntries() const +cmBTStringRange cmStateDirectory::GetCompileDefinitionsEntries() const { return GetPropertyContent( this->DirectoryState->CompileDefinitions, this->Snapshot_.Position->CompileDefinitionsPosition); } -cmBacktraceRange cmStateDirectory::GetCompileDefinitionsEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, - this->Snapshot_.Position->CompileDefinitionsPosition); -} - void cmStateDirectory::AppendCompileDefinitionsEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) + const BT<std::string>& vec) { AppendEntry(this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, - this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileDefinitionsPosition, vec); } -void cmStateDirectory::SetCompileDefinitions(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetCompileDefinitions(const BT<std::string>& vec) { SetContent(this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, - this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileDefinitionsPosition, vec); } void cmStateDirectory::ClearCompileDefinitions() { ClearContent(this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, this->Snapshot_.Position->CompileDefinitionsPosition); } -cmStringRange cmStateDirectory::GetCompileOptionsEntries() const +cmBTStringRange cmStateDirectory::GetCompileOptionsEntries() const { return GetPropertyContent(this->DirectoryState->CompileOptions, this->Snapshot_.Position->CompileOptionsPosition); } -cmBacktraceRange cmStateDirectory::GetCompileOptionsEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, - this->Snapshot_.Position->CompileOptionsPosition); -} - -void cmStateDirectory::AppendCompileOptionsEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) +void cmStateDirectory::AppendCompileOptionsEntry(const BT<std::string>& vec) { AppendEntry(this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, - this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileOptionsPosition, vec); } -void cmStateDirectory::SetCompileOptions(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetCompileOptions(const BT<std::string>& vec) { SetContent(this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, - this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileOptionsPosition, vec); } void cmStateDirectory::ClearCompileOptions() { ClearContent(this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, this->Snapshot_.Position->CompileOptionsPosition); } -cmStringRange cmStateDirectory::GetLinkOptionsEntries() const +cmBTStringRange cmStateDirectory::GetLinkOptionsEntries() const { return GetPropertyContent(this->DirectoryState->LinkOptions, this->Snapshot_.Position->LinkOptionsPosition); } -cmBacktraceRange cmStateDirectory::GetLinkOptionsEntryBacktraces() const -{ - return GetPropertyBacktraces(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, - this->Snapshot_.Position->LinkOptionsPosition); -} - -void cmStateDirectory::AppendLinkOptionsEntry(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::AppendLinkOptionsEntry(const BT<std::string>& vec) { AppendEntry(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, - this->Snapshot_.Position->LinkOptionsPosition, vec, lfbt); + this->Snapshot_.Position->LinkOptionsPosition, vec); } -void cmStateDirectory::SetLinkOptions(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetLinkOptions(const BT<std::string>& vec) { SetContent(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, - this->Snapshot_.Position->LinkOptionsPosition, vec, lfbt); + this->Snapshot_.Position->LinkOptionsPosition, vec); } void cmStateDirectory::ClearLinkOptions() { ClearContent(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, this->Snapshot_.Position->LinkOptionsPosition); } -cmStringRange cmStateDirectory::GetLinkDirectoriesEntries() const +cmBTStringRange cmStateDirectory::GetLinkDirectoriesEntries() const { return GetPropertyContent(this->DirectoryState->LinkDirectories, this->Snapshot_.Position->LinkDirectoriesPosition); } -cmBacktraceRange cmStateDirectory::GetLinkDirectoriesEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, - this->Snapshot_.Position->LinkDirectoriesPosition); -} - -void cmStateDirectory::AppendLinkDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) +void cmStateDirectory::AppendLinkDirectoriesEntry(const BT<std::string>& vec) { AppendEntry(this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, - this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); + this->Snapshot_.Position->LinkDirectoriesPosition, vec); } -void cmStateDirectory::PrependLinkDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) +void cmStateDirectory::PrependLinkDirectoriesEntry(const BT<std::string>& vec) { auto entryEnd = this->DirectoryState->LinkDirectories.begin() + this->Snapshot_.Position->LinkDirectoriesPosition; @@ -334,30 +250,22 @@ void cmStateDirectory::PrependLinkDirectoriesEntry( rbegin = std::find(rbegin, rend, cmPropertySentinal); auto entryIt = rbegin.base(); - auto entryBegin = this->DirectoryState->LinkDirectories.begin(); - - auto btIt = this->DirectoryState->LinkDirectoriesBacktraces.begin() + - std::distance(entryBegin, entryIt); this->DirectoryState->LinkDirectories.insert(entryIt, vec); - this->DirectoryState->LinkDirectoriesBacktraces.insert(btIt, lfbt); this->Snapshot_.Position->LinkDirectoriesPosition = this->DirectoryState->LinkDirectories.size(); } -void cmStateDirectory::SetLinkDirectories(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetLinkDirectories(const BT<std::string>& vec) { SetContent(this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, - this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); + this->Snapshot_.Position->LinkDirectoriesPosition, vec); } void cmStateDirectory::ClearLinkDirectories() { ClearContent(this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, this->Snapshot_.Position->LinkDirectoriesPosition); } @@ -370,7 +278,7 @@ void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, this->ClearIncludeDirectories(); return; } - this->SetIncludeDirectories(value, lfbt); + this->SetIncludeDirectories(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_OPTIONS") { @@ -378,7 +286,7 @@ void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, this->ClearCompileOptions(); return; } - this->SetCompileOptions(value, lfbt); + this->SetCompileOptions(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_DEFINITIONS") { @@ -386,7 +294,7 @@ void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, this->ClearCompileDefinitions(); return; } - this->SetCompileDefinitions(value, lfbt); + this->SetCompileDefinitions(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_OPTIONS") { @@ -394,7 +302,7 @@ void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, this->ClearLinkOptions(); return; } - this->SetLinkOptions(value, lfbt); + this->SetLinkOptions(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_DIRECTORIES") { @@ -402,7 +310,7 @@ void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, this->ClearLinkDirectories(); return; } - this->SetLinkDirectories(value, lfbt); + this->SetLinkDirectories(BT<std::string>(value, lfbt)); return; } @@ -425,23 +333,23 @@ void cmStateDirectory::AppendProperty(const std::string& prop, cmListFileBacktrace const& lfbt) { if (prop == "INCLUDE_DIRECTORIES") { - this->AppendIncludeDirectoriesEntry(value, lfbt); + this->AppendIncludeDirectoriesEntry(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_OPTIONS") { - this->AppendCompileOptionsEntry(value, lfbt); + this->AppendCompileOptionsEntry(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_DEFINITIONS") { - this->AppendCompileDefinitionsEntry(value, lfbt); + this->AppendCompileDefinitionsEntry(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_OPTIONS") { - this->AppendLinkOptionsEntry(value, lfbt); + this->AppendLinkOptionsEntry(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_DIRECTORIES") { - this->AppendLinkDirectoriesEntry(value, lfbt); + this->AppendLinkDirectoriesEntry(BT<std::string>(value, lfbt)); return; } |