From: Tom Tromey Date: Tue, 9 Dec 2025 19:17:09 +0000 (-0700) Subject: Improve fputs_highlighted by using ui_file::write X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5844bd5a83304e789d0d6c579705ea40562e1318;p=thirdparty%2Fbinutils-gdb.git Improve fputs_highlighted by using ui_file::write 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 --- diff --git a/gdb/utils.c b/gdb/utils.c index 80b08f4e211..cdb167c76cd 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -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. */