Use HashMap for DexFileVerifier
Before:
2.51% std::map<unsigned int, unsigned short>::insert(...
0.72% malloc
After:
0.73% art::HashSet<std::__1::pair<unsigned int, unsigned short>::Insert(...
0.57% malloc
The allocation from HashSet is only 0.71% of the remaining 0.57% malloc time.
0.71% art::DexFileVerifier::CheckIntraSectionIterate(unsigned long, unsigned int, unsigned short)
Bug: 10921004
Change-Id: I85c60bf27fb2d9976b944fc15d8401904432dc22
diff --git a/runtime/base/allocator.h b/runtime/base/allocator.h
index ad255b8..969f5b9 100644
--- a/runtime/base/allocator.h
+++ b/runtime/base/allocator.h
@@ -22,6 +22,7 @@
#include <unordered_map>
#include "atomic.h"
+#include "base/hash_map.h"
#include "base/macros.h"
#include "base/mutex.h"
#include "base/type_static_if.h"
@@ -170,6 +171,14 @@
using AllocationTrackingUnorderedMap = std::unordered_map<
Key, T, Hash, Pred, TrackingAllocator<std::pair<const Key, T>, kTag>>;
+template<class Key,
+ class T,
+ class EmptyFn,
+ AllocatorTag kTag,
+ class Hash = std::hash<Key>,
+ class Pred = std::equal_to<Key>>
+using AllocationTrackingHashMap = HashMap<
+ Key, T, EmptyFn, Hash, Pred, TrackingAllocator<std::pair<Key, T>, kTag>>;
} // namespace art
#endif // ART_RUNTIME_BASE_ALLOCATOR_H_