Some style review suggestions.

This commit is contained in:
Daniel Kirchner 2021-01-13 12:43:38 +01:00
parent 4505889481
commit 91cdb606a5
2 changed files with 16 additions and 16 deletions

View File

@ -23,30 +23,30 @@ namespace solidity::cxx20
{
// Taken from https://en.cppreference.com/w/cpp/container/map/erase_if.
template< class Key, class T, class Compare, class Alloc, class Pred >
typename std::map<Key,T,Compare,Alloc>::size_type erase_if(std::map<Key,T,Compare,Alloc>& c, Pred pred)
template<class Key, class T, class Compare, class Alloc, class Pred>
typename std::map<Key, T, Compare, Alloc>::size_type erase_if(std::map<Key,T,Compare,Alloc>& _c, Pred _pred)
{
auto old_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;)
if (pred(*i))
i = c.erase(i);
auto old_size = _c.size();
for (auto i = _c.begin(), last = _c.end(); i != last;)
if (_pred(*i))
i = _c.erase(i);
else
++i;
return old_size - c.size();
return old_size - _c.size();
}
// Taken from https://en.cppreference.com/w/cpp/container/unordered_map/erase_if.
template<class Key, class T, class Hash, class KeyEqual, class Alloc, class Pred>
typename std::unordered_map<Key,T,Hash,KeyEqual,Alloc>::size_type
erase_if(std::unordered_map<Key,T,Hash,KeyEqual,Alloc>& c, Pred pred)
typename std::unordered_map<Key, T, Hash, KeyEqual, Alloc>::size_type
erase_if(std::unordered_map<Key, T, Hash, KeyEqual, Alloc>& _c, Pred _pred)
{
auto old_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;)
if (pred(*i))
i = c.erase(i);
auto old_size = _c.size();
for (auto i = _c.begin(), last = _c.end(); i != last;)
if (_pred(*i))
i = _c.erase(i);
else
++i;
return old_size - c.size();
return old_size - _c.size();
}
}

View File

@ -325,9 +325,9 @@ void DataFlowAnalyzer::clearValues(set<YulString> _variables)
cxx20::erase_if(m_memory, eraseCondition);
// Also clear variables that reference variables to be cleared.
for (auto const& name: _variables)
for (auto const& variableToClear: _variables)
for (auto const& [ref, names]: m_references)
if (names.count(name))
if (names.count(variableToClear))
_variables.emplace(ref);
// Clear the value and update the reference relation.