From 02293841e742c14a18155bc0e10c39462c97dcbf Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 10 May 2019 11:22:38 +0200 Subject: Ninja: Simplify cmGlobalNinjaGenerator::AddRule and HasRule methods - Use `std::unordered_set` for the emitted rule register - Use `std::unordered_map` for command length register --- Source/cmGlobalNinjaGenerator.cxx | 12 +++++------- Source/cmGlobalNinjaGenerator.h | 9 +++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 06234aa..684a679 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -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(command.size()); + // Write rule cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream, name, command, description, comment, depfile, deptype, rspfile, rspcontent, restat, generator); - - this->RuleCmdLength[name] = static_cast(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 diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index efd1d8f..4cd1a98 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -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 RulesSetType; - /// The set of rules added to the generated build system. - RulesSetType Rules; + std::unordered_set Rules; /// Length of rule command, used by rsp file evaluation - std::map RuleCmdLength; + std::unordered_map RuleCmdLength; /// The set of dependencies to add to the "all" target. cmNinjaDeps AllDependencies; -- cgit v0.12