diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-10-18 08:37:27 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-10-18 09:36:55 +0200 |
commit | a566a3acc84386e4738711d27a250f63e59cbb6b (patch) | |
tree | 472fc3526d8207d0842f75305e803205cbfb578d /libbuild2 | |
parent | 75d9644c125006170e773d7bf9372c4d9676e7a1 (diff) |
Optimize config::required() to move default value if possible
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/config/utility.hxx | 11 | ||||
-rw-r--r-- | libbuild2/config/utility.txx | 4 |
2 files changed, 9 insertions, 6 deletions
diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx index b1995b6..cfb7177 100644 --- a/libbuild2/config/utility.hxx +++ b/libbuild2/config/utility.hxx @@ -43,7 +43,7 @@ namespace build2 pair<lookup, bool> required (scope& root, const variable&, - const T& default_value, + T&& default_value, bool override = false, uint64_t save_flags = 0); @@ -53,12 +53,15 @@ namespace build2 inline pair<lookup, bool> required (scope& root, const string& name, - const T& default_value, + T&& default_value, bool override = false, uint64_t save_flags = 0) { - return required ( - root, root.ctx.var_pool[name], default_value, override, save_flags); + return required (root, + root.ctx.var_pool[name], + std::forward<T> (default_value), // VC14 + override, + save_flags); } inline pair<lookup, bool> diff --git a/libbuild2/config/utility.txx b/libbuild2/config/utility.txx index 9c1455f..4c4e305 100644 --- a/libbuild2/config/utility.txx +++ b/libbuild2/config/utility.txx @@ -13,7 +13,7 @@ namespace build2 pair<lookup, bool> required (scope& root, const variable& var, - const T& def_val, + T&& def_val, bool def_ovr, uint64_t save_flags) { @@ -35,7 +35,7 @@ namespace build2 // if (!l.defined () || (def_ovr && !l.belongs (root))) { - value& v (root.assign (var) = def_val); + value& v (root.assign (var) = std::forward<T> (def_val)); // VC14 v.extra = true; // Default value flag. n = (save_flags & save_commented) == 0; // Absence means default. |