From 4028bdef7d36ff41d8143358edec710db64560a4 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 15 Oct 2015 10:42:43 +0200 Subject: [PATCH] introduce rule cache (no need to figure out rlist every time) --- main.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.cc b/main.cc index 9efbae3..0af05e9 100644 --- a/main.cc +++ b/main.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ using ostd::ConstCharRange; using ostd::Vector; +using ostd::Map; using ostd::String; using ostd::Uint32; using ostd::slice_until; @@ -161,6 +163,8 @@ struct ObState { Rule *rule; }; + Map> cache; + template int error(int retcode, ConstCharRange fmt, A &&...args) { ostd::err.write(progname, ": "); @@ -242,8 +246,9 @@ struct ObState { return 0; } - int exec_rule(ConstCharRange target, ConstCharRange from = nullptr) { - Vector rlist; + int find_rules(ConstCharRange target, Vector &rlist) { + if (!rlist.empty()) + return 0; SubRule *frule = nullptr; bool exact = false; for (auto &rule: rules.iter()) { @@ -285,6 +290,14 @@ struct ObState { } } } + return 0; + } + + int exec_rule(ConstCharRange target, ConstCharRange from = nullptr) { + Vector &rlist = cache[target]; + int fret = find_rules(target, rlist); + if (fret) + return fret; if (rlist.empty() && !ob_check_file(target)) { if (from.empty()) return error(1, "no rule to run target '%s'", target);