[binutils-gdb] Improve fputs_highlighted by using ui_file::write
Tom Tromey
tromey@sourceware.org
Mon Feb 9 15:51:22 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5844bd5a83304e789d0d6c579705ea40562e1318
commit 5844bd5a83304e789d0d6c579705ea40562e1318
Author: Tom Tromey <tom@tromey.com>
Date: Tue Dec 9 12:17:09 2025 -0700
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 <aburgess@redhat.com>
Diff:
---
gdb/utils.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
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. */
More information about the Gdb-cvs
mailing list