Revert^2 "ART: Fix some performance-X tidy"

This reverts commit 6856214f2c849600bcb94cc6e84975ba8cb69920.

Fix lifetime issue in imgdiag.

Test: mmma art
Test: m test-art-target-gtest-imgdiag_test
Change-Id: I919db6310c0713313340adfe66bcd75a1c5c236e
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index a060fd2..ad44624 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1768,7 +1768,7 @@
     writer.Finish();
     ASSERT_EQ(apk_file.GetFile()->Flush(), 0);
   }
-  const std::string dex_location = apk_file.GetFilename();
+  const std::string& dex_location = apk_file.GetFilename();
   const std::string odex_location = GetOdexDir() + "/output.odex";
   GenerateOdexForTest(dex_location,
                       odex_location,
@@ -1974,7 +1974,7 @@
         << "Failed to find candidate code item with only one code unit in last instruction.";
   });
 
-  std::string dex_location = temp_dex.GetFilename();
+  const std::string& dex_location = temp_dex.GetFilename();
   std::string odex_location = GetOdexDir() + "/quickened.odex";
   std::string vdex_location = GetOdexDir() + "/quickened.vdex";
   std::unique_ptr<File> vdex_output(OS::CreateEmptyFile(vdex_location.c_str()));
@@ -2049,7 +2049,7 @@
     writer.Finish();
     ASSERT_EQ(invalid_dex.GetFile()->Flush(), 0);
   }
-  const std::string dex_location = invalid_dex.GetFilename();
+  const std::string& dex_location = invalid_dex.GetFilename();
   const std::string odex_location = GetOdexDir() + "/output.odex";
   std::string error_msg;
   int status = GenerateOdexForTestWithStatus(
diff --git a/dex2oat/linker/arm/relative_patcher_arm_base.cc b/dex2oat/linker/arm/relative_patcher_arm_base.cc
index 7cb8ae5..a2ba339 100644
--- a/dex2oat/linker/arm/relative_patcher_arm_base.cc
+++ b/dex2oat/linker/arm/relative_patcher_arm_base.cc
@@ -251,7 +251,7 @@
       continue;
     }
     // Get the base name to use for the first occurrence of the thunk.
-    std::string base_name = data.GetDebugName();
+    const std::string& base_name = data.GetDebugName();
     for (size_t i = start, num = data.NumberOfThunks(); i != num; ++i) {
       debug::MethodDebugInfo info = {};
       if (i == 0u) {
diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc
index f148b94..2b1352d 100644
--- a/dexlayout/dexlayout_test.cc
+++ b/dexlayout/dexlayout_test.cc
@@ -468,7 +468,7 @@
     }
 
     std::vector<std::string> test_files = { dex_file, profile_file, output_dex, second_output_dex };
-    for (auto test_file : test_files) {
+    for (const std::string& test_file : test_files) {
       if (!UnlinkFile(test_file)) {
         return false;
       }
@@ -501,7 +501,7 @@
     }
 
     std::vector<std::string> dex_files = { input_dex, output_dex };
-    for (auto dex_file : dex_files) {
+    for (const std::string& dex_file : dex_files) {
       if (!UnlinkFile(dex_file)) {
         return false;
       }
diff --git a/imgdiag/imgdiag.cc b/imgdiag/imgdiag.cc
index ddb8fe1..dea92e0 100644
--- a/imgdiag/imgdiag.cc
+++ b/imgdiag/imgdiag.cc
@@ -338,7 +338,7 @@
   ImgObjectVisitor(ComputeDirtyFunc dirty_func,
                    const uint8_t* begin_image_ptr,
                    const std::set<size_t>& dirty_pages) :
-    dirty_func_(dirty_func),
+    dirty_func_(std::move(dirty_func)),
     begin_image_ptr_(begin_image_ptr),
     dirty_pages_(dirty_pages) { }
 
@@ -356,7 +356,7 @@
   }
 
  private:
-  ComputeDirtyFunc dirty_func_;
+  const ComputeDirtyFunc dirty_func_;
   const uint8_t* begin_image_ptr_;
   const std::set<size_t>& dirty_pages_;
 };
@@ -649,7 +649,7 @@
   ImgArtMethodVisitor(ComputeDirtyFunc dirty_func,
                       const uint8_t* begin_image_ptr,
                       const std::set<size_t>& dirty_pages) :
-    dirty_func_(dirty_func),
+    dirty_func_(std::move(dirty_func)),
     begin_image_ptr_(begin_image_ptr),
     dirty_pages_(dirty_pages) { }
   virtual ~ImgArtMethodVisitor() OVERRIDE { }
@@ -658,7 +658,7 @@
   }
 
  private:
-  ComputeDirtyFunc dirty_func_;
+  const ComputeDirtyFunc dirty_func_;
   const uint8_t* begin_image_ptr_;
   const std::set<size_t>& dirty_pages_;
 };
diff --git a/libartbase/base/variant_map_test.cc b/libartbase/base/variant_map_test.cc
index 4677b6d..f2da338 100644
--- a/libartbase/base/variant_map_test.cc
+++ b/libartbase/base/variant_map_test.cc
@@ -108,7 +108,7 @@
   EXPECT_EQ(size_t(2), fmFilled.Size());
 
   // Test copy constructor
-  FruitMap fmEmptyCopy(fmEmpty);
+  FruitMap fmEmptyCopy(fmEmpty);  // NOLINT
   EXPECT_EQ(size_t(0), fmEmptyCopy.Size());
 
   // Test copy constructor
diff --git a/libdexfile/dex/dex_instruction_test.cc b/libdexfile/dex/dex_instruction_test.cc
index c944085..6ce9dba 100644
--- a/libdexfile/dex/dex_instruction_test.cc
+++ b/libdexfile/dex/dex_instruction_test.cc
@@ -135,7 +135,7 @@
 static void Build35c(uint16_t* out,
                      Instruction::Code code,
                      uint16_t method_idx,
-                     std::vector<uint16_t> args) {
+                     const std::vector<uint16_t>& args) {
   out[0] = 0;
   out[0] |= (args.size() << 12);
   out[0] |= static_cast<uint16_t>(code);
@@ -152,7 +152,7 @@
 
 static std::string DumpInst35c(Instruction::Code code,
                                uint16_t method_idx,
-                               std::vector<uint16_t> args) {
+                               const std::vector<uint16_t>& args) {
   uint16_t inst[6] = {};
   Build35c(inst, code, method_idx, args);
   return Instruction::At(inst)->DumpString(nullptr);
diff --git a/libprofile/profile/profile_compilation_info.cc b/libprofile/profile/profile_compilation_info.cc
index 748e24e..1bb84b1 100644
--- a/libprofile/profile/profile_compilation_info.cc
+++ b/libprofile/profile/profile_compilation_info.cc
@@ -1383,7 +1383,7 @@
   // the current profile info.
   // Note that the number of elements should be very small, so this should not
   // be a performance issue.
-  for (const ProfileLineHeader other_profile_line_header : profile_line_headers) {
+  for (const ProfileLineHeader& other_profile_line_header : profile_line_headers) {
     if (!filter_fn(other_profile_line_header.dex_location, other_profile_line_header.checksum)) {
       continue;
     }
diff --git a/profman/profman.cc b/profman/profman.cc
index 5fbce66..9b47097 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -389,7 +389,7 @@
   }
 
   bool OpenApkFilesFromLocations(
-      std::function<void(std::unique_ptr<const DexFile>&&)> process_fn) {
+      const std::function<void(std::unique_ptr<const DexFile>&&)>& process_fn) {
     bool use_apk_fd_list = !apks_fd_.empty();
     if (use_apk_fd_list) {
       // Get the APKs from the collection of FDs.
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 10fa8c5..cbd9880 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -1822,7 +1822,7 @@
 
 std::string ConcurrentCopying::DumpReferenceInfo(mirror::Object* ref,
                                                  const char* ref_name,
-                                                 std::string indent) {
+                                                 const char* indent) {
   std::ostringstream oss;
   oss << indent << heap_->GetVerification()->DumpObjectInfo(ref, ref_name) << '\n';
   if (ref != nullptr) {
@@ -1846,13 +1846,13 @@
                                                  MemberOffset offset,
                                                  mirror::Object* ref) {
   std::ostringstream oss;
-  std::string indent = "  ";
-  oss << indent << "Invalid reference: ref=" << ref
+  constexpr const char* kIndent = "  ";
+  oss << kIndent << "Invalid reference: ref=" << ref
       << " referenced from: object=" << obj << " offset= " << offset << '\n';
   // Information about `obj`.
-  oss << DumpReferenceInfo(obj, "obj", indent) << '\n';
+  oss << DumpReferenceInfo(obj, "obj", kIndent) << '\n';
   // Information about `ref`.
-  oss << DumpReferenceInfo(ref, "ref", indent);
+  oss << DumpReferenceInfo(ref, "ref", kIndent);
   return oss.str();
 }
 
@@ -1928,10 +1928,10 @@
 
 std::string ConcurrentCopying::DumpGcRoot(mirror::Object* ref) {
   std::ostringstream oss;
-  std::string indent = "  ";
-  oss << indent << "Invalid GC root: ref=" << ref << '\n';
+  constexpr const char* kIndent = "  ";
+  oss << kIndent << "Invalid GC root: ref=" << ref << '\n';
   // Information about `ref`.
-  oss << DumpReferenceInfo(ref, "ref", indent);
+  oss << DumpReferenceInfo(ref, "ref", kIndent);
   return oss.str();
 }
 
diff --git a/runtime/gc/collector/concurrent_copying.h b/runtime/gc/collector/concurrent_copying.h
index f1e7e2f..448525d 100644
--- a/runtime/gc/collector/concurrent_copying.h
+++ b/runtime/gc/collector/concurrent_copying.h
@@ -242,7 +242,7 @@
       REQUIRES_SHARED(Locks::mutator_lock_);
   // Dump information about reference `ref` and return it as a string.
   // Use `ref_name` to name the reference in messages. Each message is prefixed with `indent`.
-  std::string DumpReferenceInfo(mirror::Object* ref, const char* ref_name, std::string indent = "")
+  std::string DumpReferenceInfo(mirror::Object* ref, const char* ref_name, const char* indent = "")
       REQUIRES_SHARED(Locks::mutator_lock_);
   // Dump information about heap reference `ref`, referenced from object `obj` at offset `offset`,
   // and return it as a string.
diff --git a/runtime/subtype_check_info_test.cc b/runtime/subtype_check_info_test.cc
index 91fcc07..e40bca5 100644
--- a/runtime/subtype_check_info_test.cc
+++ b/runtime/subtype_check_info_test.cc
@@ -121,11 +121,11 @@
     return SubtypeCheckInfo::MakeUnchecked(bs, overflow, depth);
   }
 
-  static bool HasNext(SubtypeCheckInfo io) {
+  static bool HasNext(const SubtypeCheckInfo& io) {
     return io.HasNext();
   }
 
-  static BitString GetPathToRoot(SubtypeCheckInfo io) {
+  static BitString GetPathToRoot(const SubtypeCheckInfo& io) {
     return io.GetPathToRoot();
   }
 
diff --git a/runtime/subtype_check_test.cc b/runtime/subtype_check_test.cc
index 979fa42..666bf81 100644
--- a/runtime/subtype_check_test.cc
+++ b/runtime/subtype_check_test.cc
@@ -654,13 +654,15 @@
     MockClass* klass,
     size_t cur_depth,
     size_t total_depth,
-    std::vector<std::pair<SubtypeCheckInfo::State, SubtypeCheckInfo::State>> transitions) {
+    const std::vector<std::pair<SubtypeCheckInfo::State, SubtypeCheckInfo::State>>& transitions) {
   MockScopedLockSubtypeCheck lock_a;
   MockScopedLockMutator lock_b;
   using SCTree = MockSubtypeCheck;
 
   ASSERT_EQ(cur_depth, klass->Depth());
-  ApplyTransition(SCTree::Lookup(klass), transitions[cur_depth].first, transitions[cur_depth].second);
+  ApplyTransition(SCTree::Lookup(klass),
+                  transitions[cur_depth].first,
+                  transitions[cur_depth].second);
 
   if (total_depth == cur_depth + 1) {
     return;
@@ -676,7 +678,7 @@
 void EnsureStateChangedTest(
     MockClass* root,
     size_t depth,
-    std::vector<std::pair<SubtypeCheckInfo::State, SubtypeCheckInfo::State>> transitions) {
+    const std::vector<std::pair<SubtypeCheckInfo::State, SubtypeCheckInfo::State>>& transitions) {
   ASSERT_EQ(depth, transitions.size());
 
   EnsureStateChangedTestRecursive(root, /*cur_depth*/0u, depth, transitions);
diff --git a/sigchainlib/sigchain_test.cc b/sigchainlib/sigchain_test.cc
index 1d1e54f..9584ded 100644
--- a/sigchainlib/sigchain_test.cc
+++ b/sigchainlib/sigchain_test.cc
@@ -70,7 +70,7 @@
 };
 
 
-static void TestSignalBlocking(std::function<void()> fn) {
+static void TestSignalBlocking(const std::function<void()>& fn) {
   // Unblock SIGSEGV, make sure it stays unblocked.
   sigset64_t mask;
   sigemptyset64(&mask);
diff --git a/tools/wrapagentproperties/wrapagentproperties.cc b/tools/wrapagentproperties/wrapagentproperties.cc
index 8b4b062..77e19e6 100644
--- a/tools/wrapagentproperties/wrapagentproperties.cc
+++ b/tools/wrapagentproperties/wrapagentproperties.cc
@@ -245,7 +245,7 @@
 
 static jint CallNextAgent(StartType start,
                           ProxyJavaVM* vm,
-                          std::string options,
+                          const std::string& options,
                           void* reserved) {
   // TODO It might be good to set it up so that the library is unloaded even if no jvmtiEnv's are
   // created but this isn't expected to be common so we will just not bother.