From 8d2e541ab1aa24140eb680fb046e49a4a3f0bbd2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 12 Oct 2016 14:51:27 +0200 Subject: Various design/implementation cleanups --- build2/variable.ixx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'build2/variable.ixx') diff --git a/build2/variable.ixx b/build2/variable.ixx index 393a796..5c9118b 100644 --- a/build2/variable.ixx +++ b/build2/variable.ixx @@ -591,12 +591,33 @@ namespace build2 // variable_pool // - inline const variable& variable_pool:: + inline const variable* variable_pool:: find (const string& n) { - auto p (variable_pool_base::insert ( - variable {n, nullptr, nullptr, variable_visibility::normal})); - return *p.first; + auto i (map_.find (&n)); + return i != map_.end () ? &i->second : nullptr; + } + + inline const variable& variable_pool:: + insert (string n) + { + // We are not overriding anything so skip the custom insert() checks. + // + auto p ( + insert ( + variable {move (n), nullptr, nullptr, variable_visibility::normal})); + + return p.first->second; + } + + + inline const variable& variable_pool:: + operator[] (const string& n) + { + if (const variable* v = find (n)) + return *v; + else + return insert (n); } // variable_map::iterator_adapter -- cgit v1.1