Skip to content

Commit adcd026

Browse files
committedJan 28, 2020
Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
1 parent 5eaf44f commit adcd026

File tree

895 files changed

+3319
-3014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

895 files changed

+3319
-3014
lines changed
 

‎clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ inline std::string
2323
joinNamespaces(const llvm::SmallVectorImpl<StringRef> &Namespaces) {
2424
if (Namespaces.empty())
2525
return "";
26-
std::string Result = Namespaces.front();
26+
std::string Result(Namespaces.front());
2727
for (auto I = Namespaces.begin() + 1, E = Namespaces.end(); I != E; ++I)
2828
Result += ("::" + *I).str();
2929
return Result;
@@ -184,7 +184,7 @@ void addReplacementOrDie(
184184
const SourceManager &SM,
185185
std::map<std::string, tooling::Replacements> *FileToReplacements) {
186186
const auto R = createReplacement(Start, End, ReplacementText, SM);
187-
auto Err = (*FileToReplacements)[R.getFilePath()].add(R);
187+
auto Err = (*FileToReplacements)[std::string(R.getFilePath())].add(R);
188188
if (Err)
189189
llvm_unreachable(llvm::toString(std::move(Err)).c_str());
190190
}
@@ -213,18 +213,18 @@ std::string getShortestQualifiedNameInNamespace(llvm::StringRef DeclName,
213213
DeclName = DeclName.ltrim(':');
214214
NsName = NsName.ltrim(':');
215215
if (DeclName.find(':') == llvm::StringRef::npos)
216-
return DeclName;
216+
return std::string(DeclName);
217217

218218
auto NsNameSplitted = splitSymbolName(NsName);
219219
auto DeclNsSplitted = splitSymbolName(DeclName);
220220
llvm::StringRef UnqualifiedDeclName = DeclNsSplitted.pop_back_val();
221221
// If the Decl is in global namespace, there is no need to shorten it.
222222
if (DeclNsSplitted.empty())
223-
return UnqualifiedDeclName;
223+
return std::string(UnqualifiedDeclName);
224224
// If NsName is the global namespace, we can simply use the DeclName sans
225225
// leading "::".
226226
if (NsNameSplitted.empty())
227-
return DeclName;
227+
return std::string(DeclName);
228228

229229
if (NsNameSplitted.front() != DeclNsSplitted.front()) {
230230
// The DeclName must be fully-qualified, but we still need to decide if a
@@ -233,7 +233,7 @@ std::string getShortestQualifiedNameInNamespace(llvm::StringRef DeclName,
233233
// to avoid conflict.
234234
if (llvm::is_contained(NsNameSplitted, DeclNsSplitted.front()))
235235
return ("::" + DeclName).str();
236-
return DeclName;
236+
return std::string(DeclName);
237237
}
238238
// Since there is already an overlap namespace, we know that `DeclName` can be
239239
// shortened, so we reduce the longest common prefix.
@@ -711,7 +711,7 @@ void ChangeNamespaceTool::moveOldNamespace(
711711
MoveNs.InsertionOffset = SM.getFileOffset(SM.getSpellingLoc(InsertionLoc));
712712
MoveNs.FID = SM.getFileID(Start);
713713
MoveNs.SourceMgr = Result.SourceManager;
714-
MoveNamespaces[SM.getFilename(Start)].push_back(MoveNs);
714+
MoveNamespaces[std::string(SM.getFilename(Start))].push_back(MoveNs);
715715
}
716716

717717
// Removes a class forward declaration from the code in the moved namespace and
@@ -762,7 +762,7 @@ void ChangeNamespaceTool::moveClassForwardDeclaration(
762762
InsertForwardDeclaration InsertFwd;
763763
InsertFwd.InsertionOffset = Insertion.getOffset();
764764
InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();
765-
InsertFwdDecls[Insertion.getFilePath()].push_back(InsertFwd);
765+
InsertFwdDecls[std::string(Insertion.getFilePath())].push_back(InsertFwd);
766766
}
767767

768768
// Replaces a qualified symbol (in \p DeclCtx) that refers to a declaration \p
@@ -816,7 +816,7 @@ void ChangeNamespaceTool::replaceQualifiedSymbolInDeclContext(
816816
->getQualifiedNameAsString())) {
817817
FromDeclNameRef = FromDeclNameRef.drop_front(2);
818818
if (FromDeclNameRef.size() < ReplaceName.size())
819-
ReplaceName = FromDeclNameRef;
819+
ReplaceName = std::string(FromDeclNameRef);
820820
}
821821
}
822822
// Checks if there is any namespace alias declarations that can shorten the

‎clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ llvm::ErrorOr<std::vector<std::string>> GetWhiteListedSymbolPatterns() {
9191
llvm::StringRef Content = File.get()->getBuffer();
9292
Content.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
9393
for (auto Line : Lines)
94-
Patterns.push_back(Line.trim());
94+
Patterns.push_back(std::string(Line.trim()));
9595
return Patterns;
9696
}
9797

0 commit comments

Comments
 (0)
Please sign in to comment.