Replace MergeSets() with std::set::merge().

And clear up ownership of the VerifierDeps being merged
by using std::unique_ptr<>.

Test: m test-art-host-gtest
Test: testrunner.py --host
Bug: 123750182
Change-Id: Id4ffa9f9fa1968fa762b9e825f25827240f6d45d
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 56333b6..d9c0bf3 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -1928,10 +1928,10 @@
     // Merge all VerifierDeps into the main one.
     verifier::VerifierDeps* verifier_deps = Thread::Current()->GetVerifierDeps();
     for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) {
-      verifier::VerifierDeps* thread_deps = worker->GetThread()->GetVerifierDeps();
-      worker->GetThread()->SetVerifierDeps(nullptr);
-      verifier_deps->MergeWith(*thread_deps, GetCompilerOptions().GetDexFilesForOatFile());
-      delete thread_deps;
+      std::unique_ptr<verifier::VerifierDeps> thread_deps(worker->GetThread()->GetVerifierDeps());
+      worker->GetThread()->SetVerifierDeps(nullptr);  // We just took ownership.
+      verifier_deps->MergeWith(std::move(thread_deps),
+                               GetCompilerOptions().GetDexFilesForOatFile());
     }
     Thread::Current()->SetVerifierDeps(nullptr);
   }
diff --git a/dexlayout/dex_verify.cc b/dexlayout/dex_verify.cc
index 718d66f..83a7c69 100644
--- a/dexlayout/dex_verify.cc
+++ b/dexlayout/dex_verify.cc
@@ -22,6 +22,8 @@
 
 #include <inttypes.h>
 
+#include <set>
+
 #include "android-base/stringprintf.h"
 
 namespace art {
diff --git a/dexlayout/dexlayout.h b/dexlayout/dexlayout.h
index 535f789..60076bf 100644
--- a/dexlayout/dexlayout.h
+++ b/dexlayout/dexlayout.h
@@ -25,6 +25,8 @@
 
 #include <stdint.h>
 #include <stdio.h>
+
+#include <set>
 #include <unordered_map>
 
 #include "dex/compact_dex_level.h"
diff --git a/libartbase/base/stl_util.h b/libartbase/base/stl_util.h
index 9d944b1..1e071ce 100644
--- a/libartbase/base/stl_util.h
+++ b/libartbase/base/stl_util.h
@@ -18,7 +18,6 @@
 #define ART_LIBARTBASE_BASE_STL_UTIL_H_
 
 #include <algorithm>
-#include <set>
 #include <sstream>
 
 #include <android-base/logging.h>
@@ -136,12 +135,6 @@
   }
 };
 
-// Merge `other` entries into `to_update`.
-template <typename T>
-static inline void MergeSets(std::set<T>& to_update, const std::set<T>& other) {
-  to_update.insert(other.begin(), other.end());
-}
-
 // Returns a copy of the passed vector that doesn't memory-own its entries.
 template <typename T>
 static inline std::vector<T*> MakeNonOwningPointerVector(const std::vector<std::unique_ptr<T>>& src) {
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
index b758159..375ca75 100644
--- a/runtime/verifier/verifier_deps.cc
+++ b/runtime/verifier/verifier_deps.cc
@@ -23,7 +23,6 @@
 #include "base/indenter.h"
 #include "base/leb128.h"
 #include "base/mutex-inl.h"
-#include "base/stl_util.h"
 #include "compiler_callbacks.h"
 #include "dex/dex_file-inl.h"
 #include "mirror/class-inl.h"
@@ -46,21 +45,22 @@
 VerifierDeps::VerifierDeps(const std::vector<const DexFile*>& dex_files)
     : VerifierDeps(dex_files, /*output_only=*/ true) {}
 
-void VerifierDeps::MergeWith(const VerifierDeps& other,
+void VerifierDeps::MergeWith(std::unique_ptr<VerifierDeps> other,
                              const std::vector<const DexFile*>& dex_files) {
-  DCHECK(dex_deps_.size() == other.dex_deps_.size());
+  DCHECK(other != nullptr);
+  DCHECK_EQ(dex_deps_.size(), other->dex_deps_.size());
   for (const DexFile* dex_file : dex_files) {
     DexFileDeps* my_deps = GetDexFileDeps(*dex_file);
-    const DexFileDeps& other_deps = *other.GetDexFileDeps(*dex_file);
+    DexFileDeps& other_deps = *other->GetDexFileDeps(*dex_file);
     // We currently collect extra strings only on the main `VerifierDeps`,
     // which should be the one passed as `this` in this method.
     DCHECK(other_deps.strings_.empty());
-    MergeSets(my_deps->assignable_types_, other_deps.assignable_types_);
-    MergeSets(my_deps->unassignable_types_, other_deps.unassignable_types_);
-    MergeSets(my_deps->classes_, other_deps.classes_);
-    MergeSets(my_deps->fields_, other_deps.fields_);
-    MergeSets(my_deps->methods_, other_deps.methods_);
-    MergeSets(my_deps->unverified_classes_, other_deps.unverified_classes_);
+    my_deps->assignable_types_.merge(other_deps.assignable_types_);
+    my_deps->unassignable_types_.merge(other_deps.unassignable_types_);
+    my_deps->classes_.merge(other_deps.classes_);
+    my_deps->fields_.merge(other_deps.fields_);
+    my_deps->methods_.merge(other_deps.methods_);
+    my_deps->unverified_classes_.merge(other_deps.unverified_classes_);
   }
 }
 
diff --git a/runtime/verifier/verifier_deps.h b/runtime/verifier/verifier_deps.h
index dfd4a5c..7f71c6d 100644
--- a/runtime/verifier/verifier_deps.h
+++ b/runtime/verifier/verifier_deps.h
@@ -63,7 +63,7 @@
 
   // Merge `other` into this `VerifierDeps`'. `other` and `this` must be for the
   // same set of dex files.
-  void MergeWith(const VerifierDeps& other, const std::vector<const DexFile*>& dex_files);
+  void MergeWith(std::unique_ptr<VerifierDeps> other, const std::vector<const DexFile*>& dex_files);
 
   // Record the verification status of the class at `type_idx`.
   static void MaybeRecordVerificationStatus(const DexFile& dex_file,