Skip to content

Commit 2fce1c1

Browse files
committed
fix: avoid useless string copies
1 parent 7f57fe6 commit 2fce1c1

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,15 @@ writeFileDefinition(const ClangDocContext &CDCtx, const Location &L) {
518518
std::make_unique<TagNode>(HTMLTag::TAG_A, std::to_string(L.LineNumber));
519519
// The links to a specific line in the source code use the github /
520520
// googlesource notation so it won't work for all hosting pages.
521-
std::string LineAnchor =
522-
formatv("#{0}{1}", RepositoryLinePrefix, L.LineNumber);
523-
524-
LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
521+
LocNumberNode->Attributes.emplace_back(
522+
"href",
523+
(FileURL + formatv("#{0}{1}", CDCtx.RepositoryLinePrefix.value_or(""),
524+
L.LineNumber))
525+
.str());
525526
Node->Children.emplace_back(std::move(LocNumberNode));
526527
Node->Children.emplace_back(std::make_unique<TextNode>(" of file "));
527-
528528
auto LocFileNode = std::make_unique<TagNode>(
529529
HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
530-
531530
LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
532531
Node->Children.emplace_back(std::move(LocFileNode));
533532
return Node;

clang-tools-extra/clang-doc/MDGenerator.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ static void writeFileDefinition(const ClangDocContext &CDCtx, const Location &L,
5959
<< "*";
6060
} else {
6161

62-
std::string LineAnchor =
63-
formatv("#{0}{1}", CDCtx.RepositoryLinePrefix.value_or(""),
64-
std::to_string(L.LineNumber));
65-
66-
OS << formatv("*Defined at [{0}{1}]({0}{2})*", LineAnchor, L.Filename,
62+
OS << formatv("*Defined at [#{0}{1}{2}](#{0}{1}{3})*",
63+
CDCtx.RepositoryLinePrefix.value_or(""),
64+
std::to_string(L.LineNumber), L.Filename,
6765
StringRef{*CDCtx.RepositoryUrl});
6866
}
6967
OS << "\n\n";

0 commit comments

Comments
 (0)