https://gcc.gnu.org/g:b3b1b80477c25b6ed74c2c5d3a54a6d7a15c9a09
commit r17-4904-gb3b1b80477c25b6ed74c2c5d3a54a6d7a15c9a09 Author: linden <[email protected]> Date: Sun Sep 6 16:00:32 2026 +1200 diagnostics: take HTML tag names as const char * in source-printing to_text/to_html's tag-name helpers took std::string by value though every call site passes a literal; to_text's bodies are no-ops, so this built a string only to discard it. Take these as const char* instead: to_text's path becomes free, to_html's cost is unchanged, and the now-meaningless std::move wrappers on that side are dropped. gcc/ChangeLog: * diagnostics/source-printing.cc (to_text::push_html_tag) (to_text::push_html_tag_with_class, to_text::add_html_tag_with_class) (to_html::push_html_tag, to_html::push_html_tag_with_class) (to_html::add_html_tag_with_class): Take tag/class names as const char * rather than std::string by value. Signed-off-by: linden <[email protected]> Diff: --- gcc/diagnostics/source-printing.cc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/gcc/diagnostics/source-printing.cc b/gcc/diagnostics/source-printing.cc index db9b3c1f2410..48af87ab242c 100644 --- a/gcc/diagnostics/source-printing.cc +++ b/gcc/diagnostics/source-printing.cc @@ -445,11 +445,11 @@ struct to_text pp_emit_prefix (&m_pp); } - void push_html_tag (std::string, bool) + void push_html_tag (const char *, bool) { // no-op for text } - void push_html_tag_with_class (std::string, std::string, bool) + void push_html_tag_with_class (const char *, const char *, bool) { // no-op for text } @@ -458,7 +458,7 @@ struct to_text // no-op for text } - void add_html_tag_with_class (std::string, std::string, bool) + void add_html_tag_with_class (const char *, const char *, bool) { // no-op for text } @@ -571,19 +571,17 @@ struct to_html // no-op for HTML } - void push_html_tag (std::string name, + void push_html_tag (const char *name, bool preserve_whitespace) { - m_xp.push_tag (std::move (name), preserve_whitespace); + m_xp.push_tag (name, preserve_whitespace); } - void push_html_tag_with_class (std::string name, - std::string class_, + void push_html_tag_with_class (const char *name, + const char *class_, bool preserve_whitespace) { - m_xp.push_tag_with_class (std::move (name), - std::move (class_), - preserve_whitespace); + m_xp.push_tag_with_class (name, class_, preserve_whitespace); } void pop_html_tag (const char *expected_name) @@ -591,13 +589,12 @@ struct to_html m_xp.pop_tag (expected_name); } - void add_html_tag_with_class (std::string name, - std::string class_, + void add_html_tag_with_class (const char *name, + const char *class_, bool preserve_whitespace) { - auto element = std::make_unique<xml::element> (std::move (name), - preserve_whitespace); - element->set_attr ("class", std::move (class_)); + auto element = std::make_unique<xml::element> (name, preserve_whitespace); + element->set_attr ("class", class_); m_xp.append (std::move (element)); }
