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
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 @@
 
 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 @@
   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 @@
         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);
         }
       }
     }