aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeongik Cha <jeongik@google.com>2023-03-16 12:57:02 +0900
committerJeongik Cha <jeongik@google.com>2023-03-16 14:29:37 +0900
commit2f4ecd1728f9620adeea31d498abea7c8e66b3bf (patch)
treea4380b5daec544eb5e655022f7d27f552ddd8633
parent4566a1ad1f3393f284e9bf35fa2bb7c0e415f1ba (diff)
downloadninja-2f4ecd1728f9620adeea31d498abea7c8e66b3bf.tar.gz
Clean up WeightDataSource
1. accept rvalue reference for move 2. uses optional.or_value instead of if block Bug: 271527305 Test: m ninja Change-Id: I29f32a3fdeb866370f076e37e063c5057890e134
-rw-r--r--src/build.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/build.cc b/src/build.cc
index 65f22e0..d0d0681 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -86,8 +86,8 @@ bool DryRunCommandRunner::WaitForCommand(Result* result) {
struct WeightDataSource {
public:
- void Put(const std::string& key, int64_t value) {
- const auto& [it, inserted] = key_data_.emplace(key);
+ void Put(std::string&& key, int64_t value) {
+ const auto& [it, inserted] = key_data_.emplace(std::move(key));
if (inserted) {
map_data_.try_emplace(*it, value);
} else {
@@ -116,10 +116,7 @@ int64_t GetWeight(const WeightDataSource& data_source, Edge* edge) {
if (edge->is_phony()) {
return 1;
}
- if (const auto& opt = data_source.Get(edge->outputs_[0]->globalPath().h)) {
- return *opt;
- }
- return 1;
+ return data_source.Get(edge->outputs_[0]->globalPath().h).value_or(1);
}
} // namespace
@@ -645,7 +642,7 @@ void Builder::RefreshPriority(const std::vector<Node*>& start_nodes) {
char* idx;
int64_t weight = std::strtoll(raw_weight.c_str(), &idx, 10);
if (idx != nullptr) {
- data_source.Put(path, weight);
+ data_source.Put(std::move(path), weight);
}
}
}