[clang-tools-extra] [clang-doc][nfc] Avoid constructing SmallString in ToString method (PR #96921)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 27 09:13:26 PDT 2024
https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/96921
This patch updates the return type HTMLTag::toString from
SmallString<16> to const char*, since this API only has a single use to
emit the string into an output stream. As a result, there is no need to
construct a full heap allocated or owned string. Arguably we should
instead provide an overload to the output stream operator that performs
this action directly. However, this change is minimal, and functionally
equivalent for now.
Additionally, this patch renames ToString in the LLVM style as toString.
>From f2251efabbc1a59e87b25285f7173161e6f63d22 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 27 Jun 2024 09:13:01 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
clang-tools-extra/clang-doc/HTMLGenerator.cpp | 42 +++++++++----------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..cc5b48077faea 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -56,7 +56,7 @@ class HTMLTag {
operator bool() = delete;
bool IsSelfClosing() const;
- llvm::SmallString<16> ToString() const;
+ const char* toString() const;
private:
TagType Value;
@@ -137,42 +137,42 @@ bool HTMLTag::IsSelfClosing() const {
llvm_unreachable("Unhandled HTMLTag::TagType");
}
-llvm::SmallString<16> HTMLTag::ToString() const {
+const char* HTMLTag::toString() const {
switch (Value) {
case HTMLTag::TAG_A:
- return llvm::SmallString<16>("a");
+ return "a";
case HTMLTag::TAG_DIV:
- return llvm::SmallString<16>("div");
+ return "div";
case HTMLTag::TAG_FOOTER:
- return llvm::SmallString<16>("footer");
+ return "footer";
case HTMLTag::TAG_H1:
- return llvm::SmallString<16>("h1");
+ return "h1";
case HTMLTag::TAG_H2:
- return llvm::SmallString<16>("h2");
+ return "h2";
case HTMLTag::TAG_H3:
- return llvm::SmallString<16>("h3");
+ return "h3";
case HTMLTag::TAG_HEADER:
- return llvm::SmallString<16>("header");
+ return "header";
case HTMLTag::TAG_LI:
- return llvm::SmallString<16>("li");
+ return "li";
case HTMLTag::TAG_LINK:
- return llvm::SmallString<16>("link");
+ return "link";
case HTMLTag::TAG_MAIN:
- return llvm::SmallString<16>("main");
+ return "main";
case HTMLTag::TAG_META:
- return llvm::SmallString<16>("meta");
+ return "meta";
case HTMLTag::TAG_OL:
- return llvm::SmallString<16>("ol");
+ return "ol";
case HTMLTag::TAG_P:
- return llvm::SmallString<16>("p");
+ return "p";
case HTMLTag::TAG_SCRIPT:
- return llvm::SmallString<16>("script");
+ return "script";
case HTMLTag::TAG_SPAN:
- return llvm::SmallString<16>("span");
+ return "span";
case HTMLTag::TAG_TITLE:
- return llvm::SmallString<16>("title");
+ return "title";
case HTMLTag::TAG_UL:
- return llvm::SmallString<16>("ul");
+ return "ul";
}
llvm_unreachable("Unhandled HTMLTag::TagType");
}
@@ -191,7 +191,7 @@ void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
break;
}
OS.indent(IndentationLevel * 2);
- OS << "<" << Tag.ToString();
+ OS << "<" << Tag.toString();
for (const auto &A : Attributes)
OS << " " << A.first << "=\"" << A.second << "\"";
if (Tag.IsSelfClosing()) {
@@ -216,7 +216,7 @@ void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
}
if (!InlineChildren)
OS.indent(IndentationLevel * 2);
- OS << "</" << Tag.ToString() << ">";
+ OS << "</" << Tag.toString() << ">";
}
template <typename Derived, typename Base,
More information about the cfe-commits
mailing list