From ce10bfeaf6d4e380eaa9e464a263afc4e0845311 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Fri, 25 Oct 2013 15:19:59 -0700 Subject: [PATCH] perf(kernel/metavar): improve performance of has_assigned_metavar by avoiding for_each+exception Signed-off-by: Leonardo de Moura --- src/kernel/metavar.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/kernel/metavar.cpp b/src/kernel/metavar.cpp index 538342b72..4fffb0106 100644 --- a/src/kernel/metavar.cpp +++ b/src/kernel/metavar.cpp @@ -256,25 +256,25 @@ expr instantiate_metavars(expr const & e, substitution const & s) { } } -struct found_assigned {}; bool has_assigned_metavar(expr const & e, substitution const & s) { if (!has_metavar(e)) { return false; } else { + bool result = false; auto proc = [&](expr const & n, unsigned) { + if (result) + return false; if (!has_metavar(n)) return false; - if (is_metavar(n) && s.is_assigned(n)) - throw found_assigned(); + if (is_metavar(n) && s.is_assigned(n)) { + result = true; + return false; + } return true; }; for_each_fn visitor(proc); - try { - visitor(e); - return false; - } catch (found_assigned&) { - return true; - } + visitor(e); + return result; } }