From 43eb1e43b6b22a0343104387431db7f32a88b16c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Feb 2025 06:46:29 +0200 Subject: Optimize maybe-used diag_record It turns out the std::ostringstream member of butl::diag_record is quite expensive to construct but to never use. --- libbuild2/variable.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libbuild2/variable.cxx') diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx index 0abc360..086fa7a 100644 --- a/libbuild2/variable.cxx +++ b/libbuild2/variable.cxx @@ -1872,8 +1872,8 @@ namespace build2 // // Note: the same diagnostics as in $json.serialize(). // - diag_record dr; - dr << fail << "invalid json value: " << e; + diag_record dr (fail); + dr << "invalid json value: " << e; if (e.event) dr << info << "while serializing " << to_string (*e.event); @@ -2099,8 +2099,8 @@ namespace build2 // We will likely be trying to interpret a member name as an integer // due to the incorrect value type so issue appropriate diagnostics. // - diag_record dr; - dr << fail (sloc) << "invalid json value subscript: " << e; + diag_record dr (fail (sloc)); + dr << "invalid json value subscript: " << e; if (jv != nullptr && jv->type != json_type::object) dr << info << "json value type is " << jv->type; -- cgit v1.1