[PATCH 1/4] [gdb/cli] Skip string copy in source_cache::ensure
Tom de Vries
tdevries@suse.de
Thu Oct 12 14:47:04 GMT 2023
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 (...)
base-commit: 4b41a55fe53ce2da4823ffa3a5b94bd09bf2ab0d
--
2.35.3
More information about the Gdb-patches
mailing list