[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
Fri Jun 28 16:22:27 PDT 2024


https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/96921

>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 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=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,

>From e91fcc1a758924c209d5c2e9f80eead380996453 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Fri, 28 Jun 2024 16:22:12 -0700
Subject: [PATCH 2/2] git clang-format

Created using spr 1.3.4
---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 8b24cece84bad..d4a5ad1b675e0 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;
-  const char* c_str() const;
+  const char *c_str() const;
 
 private:
   TagType Value;
@@ -137,7 +137,7 @@ bool HTMLTag::isSelfClosing() const {
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
-const char* HTMLTag::c_str() const {
+const char *HTMLTag::c_str() const {
   switch (Value) {
   case HTMLTag::TAG_A:
     return "a";



More information about the cfe-commits mailing list