From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YBHPKu3oLGWwJS8AWB0awg (envelope-from ) for ; Mon, 16 Oct 2023 03:40:29 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AuYSmjXh; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=2thipRLL; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9F4961E0C1; Mon, 16 Oct 2023 03:40:29 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4A3391E00F for ; Mon, 16 Oct 2023 03:40:27 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC50F3858C33 for ; Mon, 16 Oct 2023 07:40:26 +0000 (GMT) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 0B0543858D32 for ; Mon, 16 Oct 2023 07:40:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B0543858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B0543858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697442016; cv=none; b=R84cIe2I/EyyCB1Vno7pK2XGpDIMSS4x1jojAYXxTlUN9JxSH/nThVpLwGkwPTMQrUiU6TiQYJafgg1JPTpyusAesAiRtlCI0qAx9pmKQT/M5ywX9GTabNOwJj9FqZhyW576SkLSDMgrYW/It/IE+fIxCQPR8dbLmyv0u9hOtxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697442016; c=relaxed/simple; bh=sceNQseoGycoHbrA0KugnWfpGKMtF2qJZKeifTKuX0I=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version: Subject:To:From; b=aL7+Ba0g573TnInhYBuodE6MfhzthltTR2rIciFmJ8LcLC9Mm+aqlcqXg+PuNgBzGdxUPkVo8Isgzg/wTIstHPVgmBXT1cb6aZIESQtBS9X8qzMYEfDn+I8YEOSHIVIyAGurhmWLos7olx7yw8E1tfy5BV6gSAfhWDeP9LoLznE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F3BA31FDCC; Mon, 16 Oct 2023 07:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697442014; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YqJNau+JajE5bgOgjbM7Y6CgSDi9XC497XzhNV1/1K8=; b=AuYSmjXhxgXYtA02tordlULXrqtpam27SMTe/21TfmGtzbdhWK8nKXOn7yx24Y6RmmKa7M /com9Db5piosP3wEZCH3RNrLgBeUBsOhw7l/Osli5/gm8rM9WxAKpe/Au9Fn7hlFmP3JRb bSakMINvedE6PIniDb+fR4/amERCnxw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697442014; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YqJNau+JajE5bgOgjbM7Y6CgSDi9XC497XzhNV1/1K8=; b=2thipRLLjtpbHdzDgNmN+pTKNZOQFscrrXYyUtybXtGPbnCr1GFFo1+2ROJQYUJ8JWHy5k A4V4+e7prZTfnGDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DFA0F133B7; Mon, 16 Oct 2023 07:40:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id k5aPNd3oLGVIawAAMHmgww (envelope-from ); Mon, 16 Oct 2023 07:40:13 +0000 Message-ID: <4a20ed6a-4be2-4f36-a2b3-6943fc616530@suse.de> Date: Mon, 16 Oct 2023 09:40:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/4] [gdb/cli] Skip string copy in source_cache::ensure Content-Language: en-US To: Lancelot SIX Cc: gdb-patches@sourceware.org References: <20231013121953.25917-1-tdevries@suse.de> <20231013121953.25917-2-tdevries@suse.de> <20231013163425.jl53xf5d7c4booy3@octopus> From: Tom de Vries In-Reply-To: <20231013163425.jl53xf5d7c4booy3@octopus> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -0.77 X-Spamd-Result: default: False [-0.77 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BAYES_HAM(-2.68)[98.61%]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(3.00)[1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org On 10/13/23 18:34, Lancelot SIX wrote: > Hi Tom, > > On Fri, Oct 13, 2023 at 02:19:50PM +0200, Tom de Vries wrote: >> In function source_cache::ensure we have: >> ... >> std::ostringstream output; >> ... >> contents = output.str(); >> ... >> The last line causes an unnecessary string copy. >> >> C++20 allows us to skip it, like this: >> ... >> contents = std::move (output).str(); >> ... > > Looking at cppreference[1], it suggests that this new C++ overload for > str should be equivalent to > > content = std::move (*output.rbuf ()).str (); > > Should we use this construct instead regardless of C++'s version and > avoid the #ifdef? That being said, I find the C++20 version easier to > read, so it's up to you. > I've played around with this a bit, and found out that I can also use "contents = std::move (output).str();" in c++11. So I've just dropped the ifdef. Thanks, - Tom > Best, > Lancelot. > > [1] https://en.cppreference.com/w/cpp/io/basic_ostringstream/str > >> >> Use the more efficient version if compiling with -std=c++20. >> >> Tested on x86_64-linux. >> --- >> gdb/source-cache.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/gdb/source-cache.c b/gdb/source-cache.c >> index 77b357cb42b..7ef54411c69 100644 >> --- a/gdb/source-cache.c >> +++ b/gdb/source-cache.c >> @@ -252,7 +252,11 @@ source_cache::ensure (struct symtab *s) >> std::istringstream input (contents); >> std::ostringstream output; >> highlighter->highlight (input, output, lang_name, fullname); >> +#if __cplusplus >= 202002L >> + contents = std::move (output).str(); >> +#else >> contents = output.str (); >> +#endif >> already_styled = true; >> } >> catch (...) >> -- >> 2.35.3 >>