From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 1/4] [gdb/cli] Skip string copy in source_cache::ensure
Date: Mon, 16 Oct 2023 11:17:45 +0200 [thread overview]
Message-ID: <20231016091748.26247-2-tdevries@suse.de> (raw)
In-Reply-To: <20231016091748.26247-1-tdevries@suse.de>
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 solution.
Tested on x86_64-linux.
---
gdb/source-cache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 77b357cb42b..ae02d2516d9 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -252,7 +252,7 @@ source_cache::ensure (struct symtab *s)
std::istringstream input (contents);
std::ostringstream output;
highlighter->highlight (input, output, lang_name, fullname);
- contents = output.str ();
+ contents = std::move (output).str ();
already_styled = true;
}
catch (...)
--
2.35.3
next prev parent reply other threads:[~2023-10-16 9:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 9:17 [PATCH v3 0/4] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-16 9:17 ` Tom de Vries [this message]
2023-10-16 9:17 ` [PATCH v3 2/4] [gdb/cli] Factor out try_source_highlight Tom de Vries
2023-10-16 9:17 ` [PATCH v3 3/4] [gdb/cli] Keep track of styling failures in source_cache Tom de Vries
2023-10-16 9:17 ` [PATCH v3 4/4] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-16 10:21 ` Lancelot SIX
2023-10-16 11:27 ` Tom de Vries
2023-10-17 0:20 ` Pedro Alves
2023-10-18 17:21 ` Tom de Vries
2023-10-16 10:23 ` [PATCH v3 0/4] " Lancelot SIX
2023-10-16 11:28 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231016091748.26247-2-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox