]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Improve fputs_highlighted by using ui_file::write
authorTom Tromey <tom@tromey.com>
Tue, 9 Dec 2025 19:17:09 +0000 (12:17 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 9 Feb 2026 15:09:10 +0000 (08:09 -0700)
I noticed that fputs_highlighted writes a single character at a time.
It's more idiomatic to use ui_file::write.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/utils.c

index 80b08f4e211ab55a835edcbaa42bd37ccceafa44..cdb167c76cd1c2f2d80627292cd6249d74136e8f 100644 (file)
@@ -1921,22 +1921,20 @@ fputs_highlighted (const char *str, const compiled_regex &highlight,
       size_t n_highlight = pmatch.rm_eo - pmatch.rm_so;
 
       /* Output the part before pmatch with current style.  */
-      while (pmatch.rm_so > 0)
+      if (pmatch.rm_so > 0)
        {
-         gdb_putc (*str, stream);
-         pmatch.rm_so--;
-         str++;
+         stream->write (str, pmatch.rm_so);
+         str += pmatch.rm_so;
        }
 
       /* Output pmatch with the highlight style.  */
-      stream->emit_style_escape (highlight_style.style ());
-      while (n_highlight > 0)
+      if (n_highlight > 0)
        {
-         gdb_putc (*str, stream);
-         n_highlight--;
-         str++;
+         stream->emit_style_escape (highlight_style.style ());
+         stream->write (str, n_highlight);
+         str += n_highlight;
+         stream->emit_style_escape (ui_file_style ());
        }
-      stream->emit_style_escape (ui_file_style ());
     }
 
   /* Output the trailing part of STR not matching HIGHLIGHT.  */