From 8ed4bb844908de8bf2623bd6739da463fe83ef0b Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Fri, 20 Sep 2019 00:08:27 +0300 Subject: Small constifications (#1647) * build: constify EdgeWanted() * build: constify a bit of CommandRunner * graph: constify functions of struct Edge Signed-off-by: Konstantin Kharlamov --- src/build.cc | 10 +++++----- src/build.h | 4 ++-- src/build_test.cc | 4 ++-- src/graph.cc | 6 +++--- src/graph.h | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/build.cc b/src/build.cc index 8ef88b5..931fb95 100644 --- a/src/build.cc +++ b/src/build.cc @@ -47,7 +47,7 @@ struct DryRunCommandRunner : public CommandRunner { virtual ~DryRunCommandRunner() {} // Overridden from CommandRunner: - virtual bool CanRunMore(); + virtual bool CanRunMore() const; virtual bool StartCommand(Edge* edge); virtual bool WaitForCommand(Result* result); @@ -55,7 +55,7 @@ struct DryRunCommandRunner : public CommandRunner { queue finished_; }; -bool DryRunCommandRunner::CanRunMore() { +bool DryRunCommandRunner::CanRunMore() const { return true; } @@ -373,7 +373,7 @@ bool Plan::AddSubTarget(Node* node, Node* dependent, string* err, return true; } -void Plan::EdgeWanted(Edge* edge) { +void Plan::EdgeWanted(const Edge* edge) { ++wanted_edges_; if (!edge->is_phony()) ++command_edges_; @@ -668,7 +668,7 @@ void Plan::Dump() { struct RealCommandRunner : public CommandRunner { explicit RealCommandRunner(const BuildConfig& config) : config_(config) {} virtual ~RealCommandRunner() {} - virtual bool CanRunMore(); + virtual bool CanRunMore() const; virtual bool StartCommand(Edge* edge); virtual bool WaitForCommand(Result* result); virtual vector GetActiveEdges(); @@ -691,7 +691,7 @@ void RealCommandRunner::Abort() { subprocs_.Clear(); } -bool RealCommandRunner::CanRunMore() { +bool RealCommandRunner::CanRunMore() const { size_t subproc_number = subprocs_.running_.size() + subprocs_.finished_.size(); return (int)subproc_number < config_.parallelism diff --git a/src/build.h b/src/build.h index ab59f0c..410d4a5 100644 --- a/src/build.h +++ b/src/build.h @@ -108,7 +108,7 @@ private: kWantToFinish }; - void EdgeWanted(Edge* edge); + void EdgeWanted(const Edge* edge); bool EdgeMaybeReady(map::iterator want_e, string* err); /// Submits a ready edge as a candidate for execution. @@ -138,7 +138,7 @@ private: /// RealCommandRunner is an implementation that actually runs commands. struct CommandRunner { virtual ~CommandRunner() {} - virtual bool CanRunMore() = 0; + virtual bool CanRunMore() const = 0; virtual bool StartCommand(Edge* edge) = 0; /// The result of waiting for a command. diff --git a/src/build_test.cc b/src/build_test.cc index b5dbc6c..ddf8574 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -470,7 +470,7 @@ struct FakeCommandRunner : public CommandRunner { max_active_edges_(1), fs_(fs) {} // CommandRunner impl - virtual bool CanRunMore(); + virtual bool CanRunMore() const; virtual bool StartCommand(Edge* edge); virtual bool WaitForCommand(Result* result); virtual vector GetActiveEdges(); @@ -569,7 +569,7 @@ void BuildTest::RebuildTarget(const string& target, const char* manifest, builder.command_runner_.release(); } -bool FakeCommandRunner::CanRunMore() { +bool FakeCommandRunner::CanRunMore() const { return active_edges_.size() < max_active_edges_; } diff --git a/src/graph.cc b/src/graph.cc index 376b911..b8b870b 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -406,16 +406,16 @@ std::string Edge::GetBinding(const std::string& key) const { return env.LookupVariable(key); } -bool Edge::GetBindingBool(const string& key) { +bool Edge::GetBindingBool(const string& key) const { return !GetBinding(key).empty(); } -string Edge::GetUnescapedDepfile() { +string Edge::GetUnescapedDepfile() const { EdgeEnv env(this, EdgeEnv::kDoNotEscape); return env.LookupVariable("depfile"); } -string Edge::GetUnescapedDyndep() { +string Edge::GetUnescapedDyndep() const { EdgeEnv env(this, EdgeEnv::kDoNotEscape); return env.LookupVariable("dyndep"); } diff --git a/src/graph.h b/src/graph.h index 6122837..19b25c4 100644 --- a/src/graph.h +++ b/src/graph.h @@ -159,12 +159,12 @@ struct Edge { /// Returns the shell-escaped value of |key|. std::string GetBinding(const string& key) const; - bool GetBindingBool(const string& key); + bool GetBindingBool(const string& key) const; /// Like GetBinding("depfile"), but without shell escaping. - string GetUnescapedDepfile(); + string GetUnescapedDepfile() const; /// Like GetBinding("dyndep"), but without shell escaping. - string GetUnescapedDyndep(); + string GetUnescapedDyndep() const; /// Like GetBinding("rspfile"), but without shell escaping. std::string GetUnescapedRspfile() const; -- cgit v0.12