mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-26 00:00:39 -05:00
cmArgumentParser: Track pending keyword explicitly
Avoid allocating missing keyword vector unnecessarily.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user