forked from OctaForge/OctaBuild
introduce rule cache (no need to figure out rlist every time)
parent
49812b6b40
commit
4028bdef7d
17
main.cc
17
main.cc
|
@ -4,6 +4,7 @@
|
||||||
#include <ostd/types.hh>
|
#include <ostd/types.hh>
|
||||||
#include <ostd/string.hh>
|
#include <ostd/string.hh>
|
||||||
#include <ostd/vector.hh>
|
#include <ostd/vector.hh>
|
||||||
|
#include <ostd/map.hh>
|
||||||
#include <ostd/atomic.hh>
|
#include <ostd/atomic.hh>
|
||||||
#include <ostd/filesystem.hh>
|
#include <ostd/filesystem.hh>
|
||||||
#include <ostd/platform.hh>
|
#include <ostd/platform.hh>
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
|
|
||||||
using ostd::ConstCharRange;
|
using ostd::ConstCharRange;
|
||||||
using ostd::Vector;
|
using ostd::Vector;
|
||||||
|
using ostd::Map;
|
||||||
using ostd::String;
|
using ostd::String;
|
||||||
using ostd::Uint32;
|
using ostd::Uint32;
|
||||||
using ostd::slice_until;
|
using ostd::slice_until;
|
||||||
|
@ -161,6 +163,8 @@ struct ObState {
|
||||||
Rule *rule;
|
Rule *rule;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Map<ConstCharRange, Vector<SubRule>> cache;
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
int error(int retcode, ConstCharRange fmt, A &&...args) {
|
int error(int retcode, ConstCharRange fmt, A &&...args) {
|
||||||
ostd::err.write(progname, ": ");
|
ostd::err.write(progname, ": ");
|
||||||
|
@ -242,8 +246,9 @@ struct ObState {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec_rule(ConstCharRange target, ConstCharRange from = nullptr) {
|
int find_rules(ConstCharRange target, Vector<SubRule> &rlist) {
|
||||||
Vector<SubRule> rlist;
|
if (!rlist.empty())
|
||||||
|
return 0;
|
||||||
SubRule *frule = nullptr;
|
SubRule *frule = nullptr;
|
||||||
bool exact = false;
|
bool exact = false;
|
||||||
for (auto &rule: rules.iter()) {
|
for (auto &rule: rules.iter()) {
|
||||||
|
@ -285,6 +290,14 @@ struct ObState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exec_rule(ConstCharRange target, ConstCharRange from = nullptr) {
|
||||||
|
Vector<SubRule> &rlist = cache[target];
|
||||||
|
int fret = find_rules(target, rlist);
|
||||||
|
if (fret)
|
||||||
|
return fret;
|
||||||
if (rlist.empty() && !ob_check_file(target)) {
|
if (rlist.empty() && !ob_check_file(target)) {
|
||||||
if (from.empty())
|
if (from.empty())
|
||||||
return error(1, "no rule to run target '%s'", target);
|
return error(1, "no rule to run target '%s'", target);
|
||||||
|
|
Loading…
Reference in New Issue