aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/config/module18
-rw-r--r--build2/config/operation.cxx11
-rw-r--r--build2/config/utility.cxx11
3 files changed, 29 insertions, 11 deletions
diff --git a/build2/config/module b/build2/config/module
index 5becfd4..7360cf6 100644
--- a/build2/config/module
+++ b/build2/config/module
@@ -5,6 +5,8 @@
#ifndef BUILD2_CONFIG_MODULE
#define BUILD2_CONFIG_MODULE
+#include <algorithm> // find_if()
+
#include <butl/prefix-map>
#include <build2/types>
@@ -29,7 +31,21 @@ namespace build2
uint64_t flags;
};
- using saved_variables = vector<saved_variable>;
+ struct saved_variables: vector<saved_variable>
+ {
+ // Normally each module only have a handful of config variables and we
+ // only do this during configuration so for now we do linear search
+ // instead of adding a map.
+ //
+ const_iterator
+ find (const variable& var) const
+ {
+ return std::find_if (
+ begin (),
+ end (),
+ [&var] (const saved_variable& v) {return var == v.var;});
+ }
+ };
struct saved_modules: butl::prefix_map<string, saved_variables, '.'>
{
diff --git a/build2/config/operation.cxx b/build2/config/operation.cxx
index faeb570..0773f00 100644
--- a/build2/config/operation.cxx
+++ b/build2/config/operation.cxx
@@ -143,7 +143,7 @@ namespace build2
{
if (l.belongs (*r))
{
- // Find config module.
+ // Find the config module.
//
if (auto* m = r->modules.lookup<const module> (module::name))
{
@@ -153,15 +153,10 @@ namespace build2
if (i != m->saved_modules.end ())
{
- // Find the variable. For now we do linear search.
+ // Find the variable.
//
const saved_variables& sv (i->second);
-
- found = find_if (
- sv.begin (),
- sv.end (),
- [&var] (const saved_variable& v) {
- return var == v.var;}) != sv.end ();
+ found = sv.find (var) != sv.end ();
// Handle that other case: if this is an override but
// the outer project itself is not being configured,
diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx
index a24f7b3..b73e852 100644
--- a/build2/config/utility.cxx
+++ b/build2/config/utility.cxx
@@ -158,9 +158,16 @@ namespace build2
i = sm.insert (string (n, 0, n.find ('.', 7)));
}
- // We assume each variable is saved/configured once.
+ // Don't insert duplicates. The config.import vars are particularly
+ // susceptible to duplication.
//
- i->second.push_back (saved_variable {var, flags});
+ saved_variables& sv (i->second);
+ auto j (sv.find (var));
+
+ if (j == sv.end ())
+ sv.push_back (saved_variable {var, flags});
+ else
+ assert (j->flags == flags);
}
}
}