Skip to content
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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions clang-tools-extra/clang-doc/HTMLGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HTMLTag {
operator bool() = delete;

bool IsSelfClosing() const;
llvm::SmallString<16> ToString() const;
const char* toString() const;
Copy link
Contributor Author

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()?

Copy link
Contributor

@PeterChou1 PeterChou1 Jun 27, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


private:
TagType Value;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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()) {
Expand All @@ -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,
Expand Down
Loading