diff --git a/libsolutil/cxx20.h b/libsolutil/cxx20.h index 69e09a005..c9589f300 100644 --- a/libsolutil/cxx20.h +++ b/libsolutil/cxx20.h @@ -49,4 +49,16 @@ erase_if(std::unordered_map& c, Pred pred) return old_size - c.size(); } +namespace ranges +{ +template +inline constexpr bool all_of(R&& r, Pred pred) +{ + for (auto it = std::begin(r), end = std::end(r); it != end; ++it) + if (!std::invoke(pred, *it)) + return false; + return true; +} +} + } diff --git a/libyul/optimiser/Rematerialiser.cpp b/libyul/optimiser/Rematerialiser.cpp index d32fd8ea6..560fdc53a 100644 --- a/libyul/optimiser/Rematerialiser.cpp +++ b/libyul/optimiser/Rematerialiser.cpp @@ -26,6 +26,8 @@ #include #include +#include + using namespace std; using namespace solidity; using namespace solidity::yul; @@ -86,10 +88,7 @@ void Rematerialiser::visit(Expression& _e) ) { assertThrow(m_referenceCounts[name] > 0, OptimizerException, ""); - bool allInScope = true; - for (auto const& ref: m_references[name]) - allInScope = allInScope && inScope(ref); - if (allInScope) + if (cxx20::ranges::all_of(m_references[name], [&](auto const& ref) { return inScope(ref); })) { // update reference counts m_referenceCounts[name]--;