summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2013-12-18 17:22:33 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2013-12-18 17:22:34 +0000
commit1d6df5bc3b21ccd8173c8b26c8a41b3480d14d86 (patch)
tree1f6d8db2471e400d0318a8cca9f0cd0ea48a7002
parent0b8f914bf7052e3dfeb3f992e42d6ce08e9c5ac9 (diff)
parenta9faa706acb5a2e571ebfbc7d20f95504b3d8cdc (diff)
Merge "Change safecast data from set to an ordered vector."
-rw-r--r--compiler/dex/verified_methods_data.cc8
-rw-r--r--compiler/dex/verified_methods_data.h4
2 files changed, 8 insertions, 4 deletions
diff --git a/compiler/dex/verified_methods_data.cc b/compiler/dex/verified_methods_data.cc
index e5b2b036a2..e6c4ddab06 100644
--- a/compiler/dex/verified_methods_data.cc
+++ b/compiler/dex/verified_methods_data.cc
@@ -131,8 +131,8 @@ bool VerifiedMethodsData::IsSafeCast(MethodReference ref, uint32_t pc) {
}
// Look up the cast address in the set of safe casts
- MethodSafeCastSet::const_iterator cast_it = it->second->find(pc);
- return cast_it != it->second->end();
+ // Use binary_search for lookup in the sorted vector.
+ return std::binary_search(it->second->begin(), it->second->end(), pc);
}
void VerifiedMethodsData::AddRejectedClass(ClassReference ref) {
@@ -338,8 +338,10 @@ VerifiedMethodsData::MethodSafeCastSet* VerifiedMethodsData::GenerateSafeCastSet
if (is_safe_cast) {
if (mscs.get() == nullptr) {
mscs.reset(new MethodSafeCastSet());
+ } else {
+ DCHECK_LT(mscs->back(), dex_pc); // Verify ordering for push_back() to the sorted vector.
}
- mscs->insert(dex_pc);
+ mscs->push_back(dex_pc);
}
}
}
diff --git a/compiler/dex/verified_methods_data.h b/compiler/dex/verified_methods_data.h
index 8d5058ab2f..d495dff7d9 100644
--- a/compiler/dex/verified_methods_data.h
+++ b/compiler/dex/verified_methods_data.h
@@ -83,7 +83,9 @@ class VerifiedMethodsData {
LOCKS_EXCLUDED(dex_gc_maps_lock_);
// Cast elision types.
- typedef std::set<uint32_t> MethodSafeCastSet;
+ // Since we're adding the dex PCs to the set in increasing order, a sorted vector
+ // is better for performance (not just memory usage), especially for large sets.
+ typedef std::vector<uint32_t> MethodSafeCastSet;
typedef SafeMap<MethodReference, const MethodSafeCastSet*,
MethodReferenceComparator> SafeCastMap;
MethodSafeCastSet* GenerateSafeCastSet(verifier::MethodVerifier* method_verifier)