Move filter to CommonData.h

This commit is contained in:
hrkrshnn 2020-12-09 11:02:21 +01:00
parent 7ea96c5583
commit 06d719e4f1
2 changed files with 16 additions and 14 deletions

View File

@ -163,6 +163,22 @@ auto applyMap(Container const& _c, Callable&& _op, OutputContainer _oc = OutputC
return _oc;
}
/// Filter a vector.
/// Returns a copy of the vector after only taking indices `i` such that `_mask[i]` is true.
template<typename T>
std::vector<T> filter(std::vector<T> const& _vec, std::vector<bool> const& _mask)
{
assert(_vec.size() == _mask.size());
std::vector<T> ret;
for (size_t i = 0; i < _mask.size(); ++i)
if (_mask[i])
ret.push_back(_vec[i]);
return ret;
}
/// Functional fold.
/// Given a container @param _c, an initial value @param _acc,
/// and a binary operator @param _binaryOp(T, U), accumulate

View File

@ -25,20 +25,6 @@
namespace solidity::yul::unusedFunctionsCommon
{
template<typename T>
std::vector<T> filter(std::vector<T> const& _vec, std::vector<bool> const& _mask)
{
yulAssert(_vec.size() == _mask.size(), "");
std::vector<T> ret;
for (size_t i = 0; i < _mask.size(); ++i)
if (_mask[i])
ret.push_back(_vec[i]);
return ret;
}
/// Returns true if applying UnusedFunctionParameterPruner is not helpful or redundant because the
/// inliner will be able to handle it anyway.
inline bool tooSimpleToBePruned(FunctionDefinition const& _f)