perf(kernel/free_vars): improve has_free_var

This commit is contained in:
Leonardo de Moura 2015-01-15 18:42:56 -08:00
parent f397da111a
commit c6290f01d0

View file

@ -17,11 +17,14 @@ bool has_free_var(expr const & e, unsigned i) {
for_each(e, [&](expr const & e, unsigned offset) {
if (found)
return false; // already found
if (closed(e))
return false; // do not search their types
unsigned n_i = i + offset;
if (n_i < i)
return false; // overflow, vidx can't be >= max unsigned
if (n_i >= get_free_var_range(e))
return false; // expression e does not contain free variables with idx >= n_i
if (is_var(e)) {
unsigned vidx = var_idx(e);
if (vidx >= offset && vidx - offset == i)
if (vidx == n_i)
found = true;
}
return true; // continue search