-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-doc][nfc] Avoid constructing SmallString in ToString method #96921
[clang-doc][nfc] Avoid constructing SmallString in ToString method #96921
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) ChangesThis patch updates the return type HTMLTag::toString from Additionally, this patch renames ToString in the LLVM style as toString. Full diff: https://github.com/llvm/llvm-project/pull/96921.diff 1 Files Affected:
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,
|
@PeterChou1 please take a look and provide some feedback. |
@@ -56,7 +56,7 @@ class HTMLTag { | |||
operator bool() = delete; | |||
|
|||
bool IsSelfClosing() const; | |||
llvm::SmallString<16> ToString() const; | |||
const char* toString() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be renamed to c_str()
or str()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more appropriate to rename it c_str since in my mind c_str equals char* and str means std::string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Created using spr 1.3.4
✅ With the latest revision this PR passed the C/C++ code formatter. |
Created using spr 1.3.4
I'd use |
Created using spr 1.3.4
I opted for |
AFAIK the long-term plan is to replace |
…lvm#96921) This patch updates the return type of HTMLTag::toString from SmallString<16> to StringRef, since this API only returns string literals. As a result, there is no need to construct a full heap allocated or owned string. Additionally, this patch renames ToString to toString to match the LLVM style guide.
This patch updates the return type of HTMLTag::toString from
SmallString<16> to StringRef, since this API only returns string
literals. As a result, there is no need to construct a full heap
allocated or owned string.
Additionally, this patch renames ToString to toString to match the LLVM
style guide.