From 0791ced957aacda1832413149f72c2ab9e63839a Mon Sep 17 00:00:00 2001 From: Nikolai Tillmann Date: Tue, 24 Oct 2023 10:48:38 -0700 Subject: [PATCH] avoid some locking functions Summary: This is a behavior-preserving change. Reviewed By: thezhangwei Differential Revision: D50439284 fbshipit-source-id: 0562ce35459fc959fe68bd7771becd13f9943c1f --- libredex/ConcurrentContainers.h | 7 +++++++ libredex/Reachability.cpp | 2 +- opt/optimize_enums/OptimizeEnums.cpp | 5 +++-- opt/virtual_merging/VirtualMerging.cpp | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libredex/ConcurrentContainers.h b/libredex/ConcurrentContainers.h index eff7edc473..24205e0505 100644 --- a/libredex/ConcurrentContainers.h +++ b/libredex/ConcurrentContainers.h @@ -1180,6 +1180,13 @@ class ConcurrentMap final return ptr->second; } + Value get_unsafe(const Key& key, Value default_value) const { + size_t slot = Hash()(key) % n_slots; + const auto& map = this->get_container(slot); + const auto* ptr = map.get(key); + return ptr ? ptr->second : default_value; + } + /* * The Boolean return value denotes whether the insertion took place. * This operation is always thread-safe. diff --git a/libredex/Reachability.cpp b/libredex/Reachability.cpp index 952c553e5a..64faa98177 100644 --- a/libredex/Reachability.cpp +++ b/libredex/Reachability.cpp @@ -2392,7 +2392,7 @@ void dump_graph(std::ostream& os, const ReachableObjectGraph& retainers_of) { if (!retainers_of.count(obj)) { return {}; } - const auto& preds = retainers_of.at(obj); + const auto& preds = retainers_of.at_unsafe(obj); std::vector preds_vec(preds.begin(), preds.end()); // Gotta sort the reachables or the output is nondeterministic. std::sort(preds_vec.begin(), preds_vec.end(), compare); diff --git a/opt/optimize_enums/OptimizeEnums.cpp b/opt/optimize_enums/OptimizeEnums.cpp index cb52d65dd7..1dd54ea570 100644 --- a/opt/optimize_enums/OptimizeEnums.cpp +++ b/opt/optimize_enums/OptimizeEnums.cpp @@ -499,8 +499,9 @@ class OptimizeEnums { [](const auto& p) { return p.first; }); std::sort(unsafe_types.begin(), unsafe_types.end(), compare_dextypes); for (auto* t : unsafe_types) { - ofs << show(t) << ":" << unsafe_enums.at(t) << "\n"; - for (auto u : unsafe_enums.at(t)) { + const auto& unsafe_enums_at_t = unsafe_enums.at_unsafe(t); + ofs << show(t) << ":" << unsafe_enums_at_t << "\n"; + for (auto u : unsafe_enums_at_t) { ++unsafe_counts[u]; } } diff --git a/opt/virtual_merging/VirtualMerging.cpp b/opt/virtual_merging/VirtualMerging.cpp index 952fa35652..8d13972cb1 100644 --- a/opt/virtual_merging/VirtualMerging.cpp +++ b/opt/virtual_merging/VirtualMerging.cpp @@ -667,7 +667,7 @@ VirtualMerging::compute_mergeable_pairs_by_virtual_scopes( walk::parallel::virtual_scopes( virtual_scopes, [&](const virt_scope::VirtualScope* virtual_scope) { MergePairsBuilder mpb(virtual_scope, ordering_provider, m_perf_config); - auto res = mpb.build(m_mergeable_scope_methods.at(virtual_scope), + auto res = mpb.build(m_mergeable_scope_methods.at_unsafe(virtual_scope), m_xstores, m_xdexes, profiles, strategy); if (!res) { return;