From 0aa7a94e1032a96a2a72cb6a82824f9fe970d412 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 Dec 2022 14:18:44 +0200 Subject: Improve empty simple value to empty list of names reduction heuristics Specifically, do not reduce typed RHS empty simple values for prepend/append and additionally for assignment provided LHS is typed and is a container. --- libbuild2/variable.txx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'libbuild2/variable.txx') diff --git a/libbuild2/variable.txx b/libbuild2/variable.txx index fda3486..2950ea0 100644 --- a/libbuild2/variable.txx +++ b/libbuild2/variable.txx @@ -229,13 +229,13 @@ namespace build2 template names_view - simple_reverse (const value& v, names& s) + simple_reverse (const value& v, names& s, bool reduce) { const T& x (v.as ()); - // Represent an empty simple value as empty name sequence rather than - // a single empty name. This way, for example, during serialization we - // end up with a much saner looking: + // Unless requested otherwise, represent an empty simple value as empty + // name sequence rather than a single empty name. This way, for example, + // during serialization we end up with a much saner looking: // // config.import.foo = // @@ -245,6 +245,8 @@ namespace build2 // if (!value_traits::empty (x)) s.emplace_back (value_traits::reverse (x)); + else if (!reduce) + s.push_back (name ()); return s; } @@ -590,7 +592,7 @@ namespace build2 template static names_view - vector_reverse (const value& v, names& s) + vector_reverse (const value& v, names& s, bool) { auto& vv (v.as> ()); s.reserve (vv.size ()); @@ -651,7 +653,8 @@ namespace build2 nullptr, // Patched above. sizeof (vector), nullptr, // No base. - &value_traits::value_type, + true, // Container. + &value_traits::value_type, // Element type. &default_dtor>, &default_copy_ctor>, &default_copy_assign>, @@ -702,7 +705,7 @@ namespace build2 template static names_view - pair_vector_reverse (const value& v, names& s) + pair_vector_reverse (const value& v, names& s, bool) { auto& vv (v.as>> ()); s.reserve (2 * vv.size ()); @@ -803,7 +806,8 @@ namespace build2 nullptr, // Patched above. sizeof (vector>), nullptr, // No base. - nullptr, // No element. + true, // Container. + nullptr, // No element (not named). &default_dtor>>, &default_copy_ctor>>, &default_copy_assign>>, @@ -882,7 +886,7 @@ namespace build2 template static names_view - map_reverse (const value& v, names& s) + map_reverse (const value& v, names& s, bool) { auto& vm (v.as> ()); s.reserve (2 * vm.size ()); @@ -983,7 +987,8 @@ namespace build2 nullptr, // Patched above. sizeof (map), nullptr, // No base. - nullptr, // No element. + true, // Container. + nullptr, // No element (not named). &default_dtor>, &default_copy_ctor>, &default_copy_assign>, -- cgit v1.1