Skip to content

Commit f841ca0

Browse files
Use StringRef::operator== instead of StringRef::equals (NFC) (#91864)
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 276 under llvm-project/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
1 parent e74a34b commit f841ca0

File tree

19 files changed

+30
-32
lines changed

19 files changed

+30
-32
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ std::error_code DataAggregator::parseMMapEvents() {
20002000
std::pair<StringRef, MMapInfo> FileMMapInfo = FileMMapInfoRes.get();
20012001
if (FileMMapInfo.second.PID == -1)
20022002
continue;
2003-
if (FileMMapInfo.first.equals("(deleted)"))
2003+
if (FileMMapInfo.first == "(deleted)")
20042004
continue;
20052005

20062006
// Consider only the first mapping of the file for any given PID

bolt/lib/Profile/DataReader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,7 @@ std::error_code DataReader::parse() {
12051205

12061206
// Add entry data for branches to another function or branches
12071207
// to entry points (including recursive calls)
1208-
if (BI.To.IsSymbol &&
1209-
(!BI.From.Name.equals(BI.To.Name) || BI.To.Offset == 0)) {
1208+
if (BI.To.IsSymbol && (BI.From.Name != BI.To.Name || BI.To.Offset == 0)) {
12101209
I = GetOrCreateFuncEntry(BI.To.Name);
12111210
I->second.EntryData.emplace_back(std::move(BI));
12121211
}

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
15501550
for (const SectionRef &Section : Obj->sections()) {
15511551
StringRef Contents = cantFail(Section.getContents());
15521552
StringRef Name = cantFail(Section.getName());
1553-
if (Name.equals(".debug_types"))
1553+
if (Name == ".debug_types")
15541554
BC.registerOrUpdateNoteSection(".debug_types", copyByteArray(Contents),
15551555
Contents.size());
15561556
}
@@ -1633,10 +1633,10 @@ void DWARFRewriter::finalizeDebugSections(
16331633
for (const SectionRef &Secs : Obj->sections()) {
16341634
StringRef Contents = cantFail(Secs.getContents());
16351635
StringRef Name = cantFail(Secs.getName());
1636-
if (Name.equals(".debug_abbrev")) {
1636+
if (Name == ".debug_abbrev") {
16371637
BC.registerOrUpdateNoteSection(".debug_abbrev", copyByteArray(Contents),
16381638
Contents.size());
1639-
} else if (Name.equals(".debug_info")) {
1639+
} else if (Name == ".debug_info") {
16401640
BC.registerOrUpdateNoteSection(".debug_info", copyByteArray(Contents),
16411641
Contents.size());
16421642
}
@@ -1771,7 +1771,7 @@ std::optional<StringRef> updateDebugData(
17711771
};
17721772
switch (SectionIter->second.second) {
17731773
default: {
1774-
if (!SectionName.equals("debug_str.dwo"))
1774+
if (SectionName != "debug_str.dwo")
17751775
errs() << "BOLT-WARNING: unsupported debug section: " << SectionName
17761776
<< "\n";
17771777
return SectionContents;
@@ -1959,7 +1959,7 @@ void DWARFRewriter::updateDWP(DWARFUnit &CU,
19591959
continue;
19601960
}
19611961

1962-
if (SectionName.equals("debug_str.dwo")) {
1962+
if (SectionName == "debug_str.dwo") {
19631963
CurStrSection = OutData;
19641964
} else {
19651965
// Since handleDebugDataPatching returned true, we already know this is

bolt/lib/Rewrite/SDTRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void SDTRewriter::readSection() {
8787

8888
StringRef Name = DE.getCStr(&Offset);
8989

90-
if (!Name.equals("stapsdt"))
90+
if (Name != "stapsdt")
9191
errs() << "BOLT-WARNING: SDT note name \"" << Name
9292
<< "\" is not expected\n";
9393

clang-tools-extra/clang-tidy/ClangTidyCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
171171
if (IgnoreCase) {
172172
if (Value.equals_insensitive(NameAndEnum.second))
173173
return NameAndEnum.first;
174-
} else if (Value.equals(NameAndEnum.second)) {
174+
} else if (Value == NameAndEnum.second) {
175175
return NameAndEnum.first;
176176
} else if (Value.equals_insensitive(NameAndEnum.second)) {
177177
Closest = NameAndEnum.second;

clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ AST_MATCHER(QualType, isEnableIf) {
2525
const NamedDecl *TypeDecl =
2626
Spec->getTemplateName().getAsTemplateDecl()->getTemplatedDecl();
2727
return TypeDecl->isInStdNamespace() &&
28-
(TypeDecl->getName().equals("enable_if") ||
29-
TypeDecl->getName().equals("enable_if_t"));
28+
(TypeDecl->getName() == "enable_if" ||
29+
TypeDecl->getName() == "enable_if_t");
3030
};
3131
const Type *BaseType = Node.getTypePtr();
3232
// Case: pointer or reference to enable_if.

clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ getContainerFromBeginEndCall(const Expr *Init, bool IsBegin, bool *IsArrow,
421421
return {};
422422
if (IsReverse && !Call->Name.consume_back("r"))
423423
return {};
424-
if (!Call->Name.empty() && !Call->Name.equals("c"))
424+
if (!Call->Name.empty() && Call->Name != "c")
425425
return {};
426426
return std::make_pair(Call->Container, Call->CallKind);
427427
}

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ IdentifierNamingCheck::getFailureInfo(
13581358
std::replace(KindName.begin(), KindName.end(), '_', ' ');
13591359

13601360
std::string Fixup = fixupWithStyle(Type, Name, Style, HNOption, ND);
1361-
if (StringRef(Fixup).equals(Name)) {
1361+
if (StringRef(Fixup) == Name) {
13621362
if (!IgnoreFailedSplit) {
13631363
LLVM_DEBUG(Location.print(llvm::dbgs(), SM);
13641364
llvm::dbgs()

clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ static bool applyAbbreviationHeuristic(
138138
const llvm::StringMap<std::string> &AbbreviationDictionary, StringRef Arg,
139139
StringRef Param) {
140140
if (AbbreviationDictionary.contains(Arg) &&
141-
Param.equals(AbbreviationDictionary.lookup(Arg)))
141+
Param == AbbreviationDictionary.lookup(Arg))
142142
return true;
143143

144144
if (AbbreviationDictionary.contains(Param) &&
145-
Arg.equals(AbbreviationDictionary.lookup(Param)))
145+
Arg == AbbreviationDictionary.lookup(Param))
146146
return true;
147147

148148
return false;

clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ determineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile,
8888
if (FileCopy.consume_front(Parts.first) &&
8989
FileCopy.consume_back(Parts.second)) {
9090
// Determine the kind of this inclusion.
91-
if (FileCopy.equals("/internal/") ||
92-
FileCopy.equals("/proto/")) {
91+
if (FileCopy == "/internal/" || FileCopy == "/proto/") {
9392
return IncludeSorter::IK_MainTUInclude;
9493
}
9594
}

clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static const NamedDecl *findDecl(const RecordDecl &RecDecl,
8686
StringRef DeclName) {
8787
for (const Decl *D : RecDecl.decls()) {
8888
if (const auto *ND = dyn_cast<NamedDecl>(D)) {
89-
if (ND->getDeclName().isIdentifier() && ND->getName().equals(DeclName))
89+
if (ND->getDeclName().isIdentifier() && ND->getName() == DeclName)
9090
return ND;
9191
}
9292
}

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
883883

884884
// -x cuda
885885
auto language = args.getLastArgValue(clang::driver::options::OPT_x);
886-
if (language.equals("cuda")) {
886+
if (language == "cuda") {
887887
res.getFrontendOpts().features.Enable(
888888
Fortran::common::LanguageFeature::CUDA);
889889
}
@@ -986,7 +986,7 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
986986
if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
987987
auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
988988
// We only allow f2018 as the given standard
989-
if (standard.equals("f2018")) {
989+
if (standard == "f2018") {
990990
res.setEnableConformanceChecks();
991991
} else {
992992
const unsigned diagID =

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ static bool isIntrinsicModuleProcedure(llvm::StringRef name) {
16071607
static bool isCoarrayIntrinsic(llvm::StringRef name) {
16081608
return name.starts_with("atomic_") || name.starts_with("co_") ||
16091609
name.contains("image") || name.ends_with("cobound") ||
1610-
name.equals("team_number");
1610+
name == "team_number";
16111611
}
16121612

16131613
/// Return the generic name of an intrinsic module procedure specific name.

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,7 @@ class RenameMSVCLibmCallees
34973497
rewriter.startOpModification(op);
34983498
auto callee = op.getCallee();
34993499
if (callee)
3500-
if (callee->equals("hypotf"))
3500+
if (*callee == "hypotf")
35013501
op.setCalleeAttr(mlir::SymbolRefAttr::get(op.getContext(), "_hypotf"));
35023502

35033503
rewriter.finalizeOpModification(op);
@@ -3514,7 +3514,7 @@ class RenameMSVCLibmFuncs
35143514
matchAndRewrite(mlir::LLVM::LLVMFuncOp op,
35153515
mlir::PatternRewriter &rewriter) const override {
35163516
rewriter.startOpModification(op);
3517-
if (op.getSymName().equals("hypotf"))
3517+
if (op.getSymName() == "hypotf")
35183518
op.setSymNameAttr(rewriter.getStringAttr("_hypotf"));
35193519
rewriter.finalizeOpModification(op);
35203520
return mlir::success();
@@ -3629,11 +3629,11 @@ class FIRToLLVMLowering
36293629
auto callee = op.getCallee();
36303630
if (!callee)
36313631
return true;
3632-
return !callee->equals("hypotf");
3632+
return *callee != "hypotf";
36333633
});
36343634
target.addDynamicallyLegalOp<mlir::LLVM::LLVMFuncOp>(
36353635
[](mlir::LLVM::LLVMFuncOp op) {
3636-
return !op.getSymName().equals("hypotf");
3636+
return op.getSymName() != "hypotf";
36373637
});
36383638
}
36393639

lld/COFF/DebugTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static bool equalsPath(StringRef path1, StringRef path2) {
465465
#if defined(_WIN32)
466466
return path1.equals_insensitive(path2);
467467
#else
468-
return path1.equals(path2);
468+
return path1 == path2;
469469
#endif
470470
}
471471

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *buf,
11281128
for (Relocation &rel : relocs()) {
11291129
// Ignore calls into the split-stack api.
11301130
if (rel.sym->getName().starts_with("__morestack")) {
1131-
if (rel.sym->getName().equals("__morestack"))
1131+
if (rel.sym->getName() == "__morestack")
11321132
morestackCalls.push_back(&rel);
11331133
continue;
11341134
}

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static bool isRelroSection(const OutputSection *sec) {
577577
// for accessing .got as well, .got and .toc need to be close enough in the
578578
// virtual address space. Usually, .toc comes just after .got. Since we place
579579
// .got into RELRO, .toc needs to be placed into RELRO too.
580-
if (sec->name.equals(".toc"))
580+
if (sec->name == ".toc")
581581
return true;
582582

583583
// .got.plt contains pointers to external function symbols. They are

lld/MachO/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
15071507
StringRef sep = sys::path::get_separator();
15081508
// real_path removes trailing slashes as part of the normalization, but
15091509
// these are meaningful for our text based stripping
1510-
if (config->osoPrefix.equals(".") || config->osoPrefix.ends_with(sep))
1510+
if (config->osoPrefix == "." || config->osoPrefix.ends_with(sep))
15111511
expanded += sep;
15121512
config->osoPrefix = saver().save(expanded.str());
15131513
}

lld/wasm/InputChunks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ uint64_t InputSection::getTombstoneForSection(StringRef name) {
519519
// If they occur in DWARF debug symbols, we want to change the pc of the
520520
// function to -1 to avoid overlapping with a valid range. However for the
521521
// debug_ranges and debug_loc sections that would conflict with the existing
522-
// meaning of -1 so we use -2.
523-
if (name.equals(".debug_ranges") || name.equals(".debug_loc"))
522+
// meaning of -1 so we use -2.
523+
if (name == ".debug_ranges" || name == ".debug_loc")
524524
return UINT64_C(-2);
525525
if (name.starts_with(".debug_"))
526526
return UINT64_C(-1);

0 commit comments

Comments
 (0)