ART: Change unordered_set to HashSet

Change defined_classes_ to a HashSet and reserve space to avoid
allocations.

Bug: 110852609
Test: m test-art-host
Change-Id: I79fa57b781257777de76362b3aff4974e0dccd36
diff --git a/libdexfile/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc
index ca62705..ee4b0e6 100644
--- a/libdexfile/dex/dex_file_verifier.cc
+++ b/libdexfile/dex/dex_file_verifier.cc
@@ -3015,6 +3015,10 @@
   const dex::MapItem* item = map->list_;
   uint32_t count = map->size_;
 
+  // Avoid allocations, reserve space ahead of time. At most the type-id limit number
+  // of type IDs can be added.
+  defined_classes_.reserve(std::min(header_->class_defs_size_, kTypeIdLimit) + 1);
+
   // Cross check the items listed in the map.
   for (; count != 0u; --count) {
     uint32_t section_offset = item->offset_;
diff --git a/libdexfile/dex/dex_file_verifier.h b/libdexfile/dex/dex_file_verifier.h
index abb48ee..737e18a 100644
--- a/libdexfile/dex/dex_file_verifier.h
+++ b/libdexfile/dex/dex_file_verifier.h
@@ -18,9 +18,9 @@
 #define ART_LIBDEXFILE_DEX_DEX_FILE_VERIFIER_H_
 
 #include <limits>
-#include <unordered_set>
 
 #include "base/hash_map.h"
+#include "base/hash_set.h"
 #include "base/safe_map.h"
 #include "class_accessor.h"
 #include "dex_file.h"
@@ -253,7 +253,7 @@
   std::string failure_reason_;
 
   // Set of type ids for which there are ClassDef elements in the dex file.
-  std::unordered_set<decltype(dex::ClassDef::class_idx_)> defined_classes_;
+  HashSet<decltype(dex::ClassDef::class_idx_)> defined_classes_;
 
   // Cached string indices for "interesting" entries wrt/ method names. Will be populated by
   // FindStringRangesForMethodNames (which is automatically called before verifying the