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/dex_file_verifier.cc b/runtime/dex_file_verifier.cc
index a5f9d09..440d696 100644
--- a/runtime/dex_file_verifier.cc
+++ b/runtime/dex_file_verifier.cc
@@ -1416,7 +1416,12 @@
}
if (IsDataSectionType(type)) {
- offset_to_type_map_.Put(aligned_offset, type);
+ if (aligned_offset == 0u) {
+ ErrorStringPrintf("Item %d offset is 0", i);
+ return false;
+ }
+ DCHECK(offset_to_type_map_.Find(aligned_offset) == offset_to_type_map_.end());
+ offset_to_type_map_.Insert(std::pair<uint32_t, uint16_t>(aligned_offset, type));
}
aligned_offset = ptr_ - begin_;
@@ -1589,7 +1594,8 @@
}
bool DexFileVerifier::CheckOffsetToTypeMap(size_t offset, uint16_t type) {
- auto it = offset_to_type_map_.find(offset);
+ DCHECK_NE(offset, 0u);
+ auto it = offset_to_type_map_.Find(offset);
if (UNLIKELY(it == offset_to_type_map_.end())) {
ErrorStringPrintf("No data map entry found @ %zx; expected %x", offset, type);
return false;