summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-17 16:25:04 (GMT)
committerBrad King <brad.king@kitware.com>2022-07-20 20:03:13 (GMT)
commit84b335c2868d245841f08656b96cad3d9df10422 (patch)
tree0804559baeed10797beb771cc9bbb8699043247a
parenta77b9c0ece8dbb2164c2c0f11c1f5368bd055f8a (diff)
downloadCMake-84b335c2868d245841f08656b96cad3d9df10422.zip
CMake-84b335c2868d245841f08656b96cad3d9df10422.tar.gz
CMake-84b335c2868d245841f08656b96cad3d9df10422.tar.bz2
cmArgumentParser: Track pending keyword explicitly
Avoid allocating missing keyword vector unnecessarily.
-rw-r--r--Source/cmArgumentParser.cxx16
-rw-r--r--Source/cmArgumentParser.h3
2 files changed, 14 insertions, 5 deletions
diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx
index 355cfdc..df008a2 100644
--- a/Source/cmArgumentParser.cxx
+++ b/Source/cmArgumentParser.cxx
@@ -78,13 +78,12 @@ void Instance::Consume(cm::string_view arg)
{
auto const it = this->Bindings.Find(arg);
if (it != this->Bindings.end()) {
+ this->FinishKeyword();
+ this->Keyword = it->first;
if (this->ParsedKeywords != nullptr) {
this->ParsedKeywords->emplace_back(it->first);
}
it->second(*this);
- if (this->ExpectValue && this->KeywordsMissingValue != nullptr) {
- this->KeywordsMissingValue->emplace_back(it->first);
- }
return;
}
@@ -98,11 +97,18 @@ void Instance::Consume(cm::string_view arg)
this->UnparsedArguments->emplace_back(arg);
}
+ this->ExpectValue = false;
+}
+
+void Instance::FinishKeyword()
+{
+ if (this->Keyword.empty()) {
+ return;
+ }
if (this->ExpectValue) {
if (this->KeywordsMissingValue != nullptr) {
- this->KeywordsMissingValue->pop_back();
+ this->KeywordsMissingValue->emplace_back(this->Keyword);
}
- this->ExpectValue = false;
}
}
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h
index 7cbef92..2d96f07 100644
--- a/Source/cmArgumentParser.h
+++ b/Source/cmArgumentParser.h
@@ -71,6 +71,7 @@ public:
for (cm::string_view arg : args) {
this->Consume(arg);
}
+ this->FinishKeyword();
}
private:
@@ -80,11 +81,13 @@ private:
std::vector<cm::string_view>* ParsedKeywords = nullptr;
void* Result = nullptr;
+ cm::string_view Keyword;
std::string* CurrentString = nullptr;
std::vector<std::string>* CurrentList = nullptr;
bool ExpectValue = false;
void Consume(cm::string_view arg);
+ void FinishKeyword();
template <typename Result>
friend class ::cmArgumentParser;