From 368009e84f4275ee9254509e74f696b5611a71c0 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Mon, 22 Oct 2018 04:25:34 +0200 Subject: [PATCH] Another trampoline bites the dust. --- src/heuristic.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/heuristic.c b/src/heuristic.c index 1a253db..94e5568 100644 --- a/src/heuristic.c +++ b/src/heuristic.c @@ -214,36 +214,44 @@ newkeylevel (const int level) return 1; } +struct state_tcc +{ + int leaves; + int nonvariables; +}; + +//! Simple helper for below +int +countMe (Term t, struct state_tcc *stcc) +{ + if (TermRunid (t) >= 0) + { + (stcc->leaves)++; + if (!isTermVariable (t)) + { + (stcc->nonvariables)++; + } + } + return 1; +} + //! count local constants float term_constcount (const System sys, Term t) { - int n, total; float ratio; + struct state_tcc Stcc; - int countMe (Term t) - { - if (TermRunid (t) >= 0) - { - total++; - if (!isTermVariable (t)) - { - n++; - } - } - return 1; - } - - n = 0; - total = 0; - term_iterate_deVar (t, countMe, NULL, NULL, NULL); - if (total == 0) + Stcc.nonvariables = 0; + Stcc.leaves = 0; + term_iterate_state_deVar (t, countMe, NULL, NULL, NULL, &Stcc); + if (Stcc.leaves == 0) { ratio = 1; } else { - ratio = ((total - n) / total); + ratio = ((Stcc.leaves - Stcc.nonvariables) / Stcc.leaves); } return ratio; }