Skip to content

Commit

Permalink
avoid some locking functions
Browse files Browse the repository at this point in the history
Summary: This is a behavior-preserving change.

Reviewed By: thezhangwei

Differential Revision: D50439284

fbshipit-source-id: 0562ce35459fc959fe68bd7771becd13f9943c1f
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Oct 24, 2023
1 parent 3f30b75 commit 0791ced
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions libredex/ConcurrentContainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion libredex/Reachability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReachableObject> preds_vec(preds.begin(), preds.end());
// Gotta sort the reachables or the output is nondeterministic.
std::sort(preds_vec.begin(), preds_vec.end(), compare);
Expand Down
5 changes: 3 additions & 2 deletions opt/optimize_enums/OptimizeEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
2 changes: 1 addition & 1 deletion opt/virtual_merging/VirtualMerging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0791ced

Please sign in to comment.