[v3,1/4,gdb/cli] Skip string copy in source_cache::ensure

Message ID 20231016091748.26247-2-tdevries@suse.de
State Committed
Headers
Series Allow source highlighting to be interrupted |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Tom de Vries Oct. 16, 2023, 9:17 a.m. UTC
  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(-)
  

Patch

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 (...)