From 5607313a91e5ca0113b1f8b9acfd02c1fb105346 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 19 Jan 2017 12:45:04 +0200 Subject: Get rid of project_name_pool With small string optimizations this is most likely a hindrance rather that an optimization. --- build2/parser.cxx | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'build2/parser.cxx') diff --git a/build2/parser.cxx b/build2/parser.cxx index 57a5618..6025082 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -2163,7 +2163,7 @@ namespace build2 const char* what, const string* separators, size_t pairn, - const string* pp, + const optional& pp, const dir_path* dp, const string* tp) { @@ -2195,7 +2195,7 @@ namespace build2 names x; // Parse into a separate list of names. parse_names_trailer ( - t, tt, x, what, separators, 0, nullptr, nullptr, nullptr); + t, tt, x, what, separators, 0, nullopt, nullptr, nullptr); if (size_t n = x.size ()) { @@ -2219,12 +2219,12 @@ namespace build2 // Move the project names. // - if (r.proj != nullptr) + if (r.proj) { - if (l.proj != nullptr) + if (l.proj) fail (loc) << "nested project name " << *r.proj; - l.proj = r.proj; + l.proj = move (r.proj); } // Merge directories. @@ -2285,7 +2285,7 @@ namespace build2 const char* what, const string* separators, size_t pairn, - const string* pp, + const optional& pp, const dir_path* dp, const string* tp) { @@ -2379,7 +2379,6 @@ namespace build2 } }; - // Number of names in the last group. This is used to detect when // we need to add an empty first pair element (e.g., @y) or when // we have a (for now unsupported) multi-name LHS (e.g., {x y}@z). @@ -2558,31 +2557,33 @@ namespace build2 // First take care of project. A project-qualified name is not very // common, so we can afford some copying for the sake of simplicity. // - const string* pp1 (pp); + optional p1; + const optional* pp1 (&pp); if (p != string::npos) { bool last (val[p] == '%'); - string::size_type p1 (last ? p : val.rfind ('%', p - 1)); + string::size_type q (last ? p : val.rfind ('%', p - 1)); - if (p1 != string::npos) + if (q != string::npos) { string proj; proj.swap (val); // First fix the rest of the name. // - val.assign (proj, p1 + 1, string::npos); - p = last ? string::npos : p - (p1 + 1); + val.assign (proj, q + 1, string::npos); + p = last ? string::npos : p - (q + 1); // Now process the project name. // - proj.resize (p1); + proj.resize (q); - if (pp != nullptr) + if (pp) fail (t) << "nested project name " << proj; - pp1 = &project_name_pool.find (proj); + p1 = move (proj); + pp1 = &p1; } } @@ -2629,7 +2630,7 @@ namespace build2 } count = parse_names_trailer ( - t, tt, ns, what, separators, pairn, pp1, dp1, tp1); + t, tt, ns, what, separators, pairn, *pp1, dp1, tp1); tt = peek (); continue; } @@ -2665,7 +2666,7 @@ namespace build2 if (dp != nullptr) dir = *dp / dir; - ns.emplace_back (pp1, + ns.emplace_back (*pp1, move (dir), (tp != nullptr ? *tp : string ()), string ()); @@ -2673,7 +2674,7 @@ namespace build2 } } - ns.emplace_back (pp1, + ns.emplace_back (*pp1, (dp != nullptr ? *dp : dir_path ()), (tp != nullptr ? *tp : string ()), move (val)); @@ -2980,14 +2981,18 @@ namespace build2 // for (const name& n: lv) { - const string* pp1 (pp); + const optional* pp1 (&pp); const dir_path* dp1 (dp); const string* tp1 (tp); - if (n.proj != 0) + optional p1; + if (n.proj) { - if (pp == nullptr) - pp1 = n.proj; + if (!pp) + { + p1 = n.proj; + pp1 = &p1; + } else fail (loc) << "nested project name " << *n.proj << " in " << what; @@ -3032,7 +3037,7 @@ namespace build2 ns.push_back (ns[pairn - 1]); } - ns.emplace_back (pp1, + ns.emplace_back (*pp1, (dp1 != nullptr ? *dp1 : dir_path ()), (tp1 != nullptr ? *tp1 : string ()), n.value); @@ -3573,7 +3578,7 @@ namespace build2 prerequisite& p ( scope_->prerequisites.insert ( - nullptr, + nullopt, dt.key (), *scope_, // Doesn't matter which scope since dir is absolute. trace).first); -- cgit v1.1