diff --git a/libredex/InitClassesWithSideEffects.cpp b/libredex/InitClassesWithSideEffects.cpp index 7e9819cd6e4..42aff14e30f 100644 --- a/libredex/InitClassesWithSideEffects.cpp +++ b/libredex/InitClassesWithSideEffects.cpp @@ -18,10 +18,10 @@ const InitClasses* InitClassesWithSideEffects::compute( const DexClass* cls, const method::ClInitHasNoSideEffectsPredicate& clinit_has_no_side_effects, const std::unordered_set* non_true_virtuals) { - auto res = - m_init_classes.get(cls->get_type(), std::shared_ptr()); - if (res) { - return res.get(); + const DexType* key = cls->get_type(); + const auto* cached = m_init_classes.get(key); + if (cached) { + return cached; } InitClasses classes; @@ -42,21 +42,12 @@ const InitClasses* InitClassesWithSideEffects::compute( super_classes->end()); } } - m_init_classes.update( - cls->get_type(), - [&res, &classes, this](const DexType*, - std::shared_ptr& value, bool exist) { - if (exist) { - always_assert(classes == *value); - } else { - if (classes.empty()) { - m_trivial_init_classes++; - } - value = std::make_shared(std::move(classes)); - } - res = value; - }); - return res.get(); + auto [ptr, emplaced] = + m_init_classes.get_or_emplace_and_assert_equal(key, std::move(classes)); + if (emplaced && ptr->empty()) { + m_trivial_init_classes++; + } + return ptr; } InitClassesWithSideEffects::InitClassesWithSideEffects( @@ -79,7 +70,7 @@ InitClassesWithSideEffects::InitClassesWithSideEffects( [&](const DexType* type) { auto it = prev_init_classes.find(type); if (it != prev_init_classes.end()) { - return it->second->empty(); + return it->second.empty(); } auto cls = type_class(type); return cls && (cls->is_external() || @@ -106,7 +97,7 @@ InitClassesWithSideEffects::InitClassesWithSideEffects( const InitClasses* InitClassesWithSideEffects::get(const DexType* type) const { auto it = m_init_classes.find(type); - return it == m_init_classes.end() ? &m_empty_init_classes : it->second.get(); + return it == m_init_classes.end() ? &m_empty_init_classes : &it->second; } const DexType* InitClassesWithSideEffects::refine(const DexType* type) const { diff --git a/libredex/InitClassesWithSideEffects.h b/libredex/InitClassesWithSideEffects.h index 0f06c253fe9..672476286c1 100644 --- a/libredex/InitClassesWithSideEffects.h +++ b/libredex/InitClassesWithSideEffects.h @@ -26,7 +26,7 @@ using InitClasses = std::vector; */ class InitClassesWithSideEffects { private: - ConcurrentMap> m_init_classes; + InsertOnlyConcurrentMap m_init_classes; std::atomic m_trivial_init_classes{0}; InitClasses m_empty_init_classes; bool m_create_init_class_insns;