Fix clang-tidy performance warnings in update_engine.

* Use const reference type for parameters, local variables,
  and for-loop index variables to avoid unnecessary copy.
* Convert some for-loops to for-rang loops.

Bug: 30407689
Bug: 30413223
Bug: 30413862
Change-Id: I78996b3f799639fc57ced45e110807625be7dcce
Test: build with WITH_TIDY=1
diff --git a/common/fake_boot_control.h b/common/fake_boot_control.h
index 5c6c160..3eccc80 100644
--- a/common/fake_boot_control.h
+++ b/common/fake_boot_control.h
@@ -85,9 +85,9 @@
     current_slot_ = slot;
   }
 
-  void SetPartitionDevice(const std::string partition_name,
+  void SetPartitionDevice(const std::string& partition_name,
                           BootControlInterface::Slot slot,
-                          const std::string device) {
+                          const std::string& device) {
     DCHECK(slot < num_slots_);
     devices_[slot][partition_name] = device;
   }
diff --git a/common/fake_hardware.h b/common/fake_hardware.h
index f7c0286..5d0fca3 100644
--- a/common/fake_hardware.h
+++ b/common/fake_hardware.h
@@ -109,15 +109,15 @@
     is_oobe_complete_ = false;
   }
 
-  void SetHardwareClass(std::string hardware_class) {
+  void SetHardwareClass(const std::string& hardware_class) {
     hardware_class_ = hardware_class;
   }
 
-  void SetFirmwareVersion(std::string firmware_version) {
+  void SetFirmwareVersion(const std::string& firmware_version) {
     firmware_version_ = firmware_version;
   }
 
-  void SetECVersion(std::string ec_version) {
+  void SetECVersion(const std::string& ec_version) {
     ec_version_ = ec_version;
   }
 
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 58d4191..7dbdf98 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -88,7 +88,7 @@
 void ExpectedEnvVars(int return_code, const string& output) {
   EXPECT_EQ(0, return_code);
   const std::set<string> allowed_envs = {"LD_LIBRARY_PATH", "PATH"};
-  for (string key_value : brillo::string_utils::Split(output, "\n")) {
+  for (const string& key_value : brillo::string_utils::Split(output, "\n")) {
     auto key_value_pair = brillo::string_utils::SplitAtFirst(
         key_value, "=", true);
     EXPECT_NE(allowed_envs.end(), allowed_envs.find(key_value_pair.first));
diff --git a/common/utils.cc b/common/utils.cc
index a352961..101e0b8 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -246,7 +246,7 @@
   return true;
 }
 
-bool WriteAll(FileDescriptorPtr fd, const void* buf, size_t count) {
+bool WriteAll(const FileDescriptorPtr& fd, const void* buf, size_t count) {
   const char* c_buf = static_cast<const char*>(buf);
   ssize_t bytes_written = 0;
   while (bytes_written < static_cast<ssize_t>(count)) {
@@ -257,7 +257,7 @@
   return true;
 }
 
-bool PWriteAll(FileDescriptorPtr fd,
+bool PWriteAll(const FileDescriptorPtr& fd,
                const void* buf,
                size_t count,
                off_t offset) {
@@ -283,7 +283,7 @@
   return true;
 }
 
-bool PReadAll(FileDescriptorPtr fd, void* buf, size_t count, off_t offset,
+bool PReadAll(const FileDescriptorPtr& fd, void* buf, size_t count, off_t offset,
               ssize_t* out_bytes_read) {
   TEST_AND_RETURN_FALSE_ERRNO(fd->Seek(offset, SEEK_SET) !=
                               static_cast<off_t>(-1));
diff --git a/common/utils.h b/common/utils.h
index 3987484..6bc030b 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -69,8 +69,8 @@
 bool WriteAll(int fd, const void* buf, size_t count);
 bool PWriteAll(int fd, const void* buf, size_t count, off_t offset);
 
-bool WriteAll(FileDescriptorPtr fd, const void* buf, size_t count);
-bool PWriteAll(FileDescriptorPtr fd,
+bool WriteAll(const FileDescriptorPtr& fd, const void* buf, size_t count);
+bool PWriteAll(const FileDescriptorPtr& fd,
                const void* buf,
                size_t count,
                off_t offset);
@@ -88,7 +88,7 @@
 bool PReadAll(int fd, void* buf, size_t count, off_t offset,
               ssize_t* out_bytes_read);
 
-bool PReadAll(FileDescriptorPtr fd, void* buf, size_t count, off_t offset,
+bool PReadAll(const FileDescriptorPtr& fd, void* buf, size_t count, off_t offset,
               ssize_t* out_bytes_read);
 
 // Opens |path| for reading and appends its entire content to the container