mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-15 02:49:42 -05:00
Ninja: Simplify cmGlobalNinjaGenerator::AddRule and HasRule methods
- Use `std::unordered_set` for the emitted rule register - Use `std::unordered_map` for command length register
This commit is contained in:
@@ -706,22 +706,20 @@ void cmGlobalNinjaGenerator::AddRule(
|
||||
const std::string& restat, bool generator)
|
||||
{
|
||||
// Do not add the same rule twice.
|
||||
if (this->HasRule(name)) {
|
||||
if (!this->Rules.insert(name).second) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->Rules.insert(name);
|
||||
// Store command length
|
||||
this->RuleCmdLength[name] = static_cast<int>(command.size());
|
||||
// Write rule
|
||||
cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream, name, command,
|
||||
description, comment, depfile, deptype,
|
||||
rspfile, rspcontent, restat, generator);
|
||||
|
||||
this->RuleCmdLength[name] = static_cast<int>(command.size());
|
||||
}
|
||||
|
||||
bool cmGlobalNinjaGenerator::HasRule(const std::string& name)
|
||||
{
|
||||
RulesSetType::const_iterator rule = this->Rules.find(name);
|
||||
return (rule != this->Rules.end());
|
||||
return (this->Rules.find(name) != this->Rules.end());
|
||||
}
|
||||
|
||||
// Private virtual overrides
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -415,15 +416,11 @@ private:
|
||||
cmGeneratedFileStream* RulesFileStream;
|
||||
cmGeneratedFileStream* CompileCommandsStream;
|
||||
|
||||
/// The type used to store the set of rules added to the generated build
|
||||
/// system.
|
||||
typedef std::set<std::string> RulesSetType;
|
||||
|
||||
/// The set of rules added to the generated build system.
|
||||
RulesSetType Rules;
|
||||
std::unordered_set<std::string> Rules;
|
||||
|
||||
/// Length of rule command, used by rsp file evaluation
|
||||
std::map<std::string, int> RuleCmdLength;
|
||||
std::unordered_map<std::string, int> RuleCmdLength;
|
||||
|
||||
/// The set of dependencies to add to the "all" target.
|
||||
cmNinjaDeps AllDependencies;
|
||||
|
||||
Reference in New Issue
Block a user