From patchwork Fri Oct 13 12:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 77656 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E73E13857C5A for ; Fri, 13 Oct 2023 12:19:55 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 94DB73858D1E for ; Fri, 13 Oct 2023 12:19:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94DB73858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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-out1.suse.de (Postfix) with ESMTPS id BA276219EC for ; Fri, 13 Oct 2023 12:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697199579; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G9NaFoBIzrjPlzub5R4sHfnE0ShCyyDtxRa1tPogMMA=; b=G8ak/6xeYnGgUXXWLVs7y5t9dtgvj7zH/a2MXLbyUW087sv30fnLEm/sLlsnVnwfqhP91u 8Px2Gi/YMfyHEgauSoHjHkuLjGcw64tgWaFexXI0GOcKSGpMKKqunbYz/fR38WtKgx/K1X EPxl5+v8E1xrNQYMZDHUYfdhkLx1nfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697199579; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G9NaFoBIzrjPlzub5R4sHfnE0ShCyyDtxRa1tPogMMA=; b=OXCUiHI1mU4rQP6MqO0oCqp0SxTCllHi4Utp7ELh+WDo4PO63TGImwFHISypAnJXICpkqM h8wdDh8hiQI77DCA== 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 A7342139ED for ; Fri, 13 Oct 2023 12:19:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sGPEJ9s1KWU0bQAAMHmgww (envelope-from ) for ; Fri, 13 Oct 2023 12:19:39 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 1/4] [gdb/cli] Skip string copy in source_cache::ensure Date: Fri, 13 Oct 2023 14:19:50 +0200 Message-Id: <20231013121953.25917-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231013121953.25917-1-tdevries@suse.de> References: <20231013121953.25917-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -1.69 X-Spamd-Result: default: False [-1.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-3.00)[-1.000]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-2.59)[98.17%] X-Spam-Status: No, score=-12.3 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+patchwork=sourceware.org@sourceware.org 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(); ... 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 (...)