perf(kernel/metavar): improve occurs_expr method

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-15 01:57:17 +01:00
parent 0f44e3c9f4
commit 46005b4ffe

View file

@ -256,18 +256,22 @@ level substitution::instantiate_metavars_wo_jst(level const & l) const {
} }
bool substitution::occurs_expr(name const & m, expr const & e) const { bool substitution::occurs_expr(name const & m, expr const & e) const {
if (!has_metavar(e)) if (!has_expr_metavar(e))
return false; return false;
auto it = find(e, [&](expr const & e, unsigned) { bool found = false;
for_each(e, [&](expr const & e, unsigned) {
if (found || !has_expr_metavar(e)) return false;
if (is_metavar(e)) { if (is_metavar(e)) {
if (mlocal_name(e) == m) if (mlocal_name(e) == m)
return true; found = true;
auto s = get_expr(e); auto s = get_expr(e);
return s && occurs_expr(m, *s); if (s && occurs_expr(m, *s))
} else { found = true;
return false; return false; // do not visit type
} }
if (is_local(e)) return false; // do not visit type
return true;
}); });
return static_cast<bool>(it); return found;
} }
} }