Skip to content

Commit bb6df08

Browse files
[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 70 under llvm/ 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 46435ac commit bb6df08

File tree

34 files changed

+79
-80
lines changed

34 files changed

+79
-80
lines changed

llvm/include/llvm/ADT/SmallString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SmallString : public SmallVector<char, InternalLen> {
8989

9090
/// Check for string equality. This is more efficient than compare() when
9191
/// the relative ordering of inequal strings isn't needed.
92-
[[nodiscard]] bool equals(StringRef RHS) const { return str().equals(RHS); }
92+
[[nodiscard]] bool equals(StringRef RHS) const { return str() == RHS; }
9393

9494
/// Check for string equality, ignoring case.
9595
[[nodiscard]] bool equals_insensitive(StringRef RHS) const {

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6896,7 +6896,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
68966896
MDString *MDS = cast<MDString>(MD->getOperand(0));
68976897
StringRef ProfName = MDS->getString();
68986898
// Check consistency of !prof branch_weights metadata.
6899-
if (!ProfName.equals("branch_weights"))
6899+
if (ProfName != "branch_weights")
69006900
continue;
69016901
unsigned ExpectedNumOperands = 0;
69026902
if (BranchInst *BI = dyn_cast<BranchInst>(&I))

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ void RuntimeDyldELF::setMipsABI(const ObjectFile &Obj) {
659659
IsMipsO32ABI = AbiVariant & ELF::EF_MIPS_ABI_O32;
660660
IsMipsN32ABI = AbiVariant & ELF::EF_MIPS_ABI2;
661661
}
662-
IsMipsN64ABI = Obj.getFileFormatName().equals("elf64-mips");
662+
IsMipsN64ABI = Obj.getFileFormatName() == "elf64-mips";
663663
}
664664

665665
// Return the .TOC. section and offset.

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Expected<NumericVariable *> Pattern::parseNumericVariableDefinition(
374374
Expected<std::unique_ptr<NumericVariableUse>> Pattern::parseNumericVariableUse(
375375
StringRef Name, bool IsPseudo, std::optional<size_t> LineNumber,
376376
FileCheckPatternContext *Context, const SourceMgr &SM) {
377-
if (IsPseudo && !Name.equals("@LINE"))
377+
if (IsPseudo && Name != "@LINE")
378378
return ErrorDiagnostic::get(
379379
SM, Name, "invalid pseudo numeric variable '" + Name + "'");
380380

llvm/lib/FuzzMutate/FuzzerCLI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void llvm::parseFuzzerCLOpts(int ArgC, char *ArgV[]) {
2121

2222
int I = 1;
2323
while (I < ArgC)
24-
if (StringRef(ArgV[I++]).equals("-ignore_remaining_args=1"))
24+
if (StringRef(ArgV[I++]) == "-ignore_remaining_args=1")
2525
break;
2626
while (I < ArgC)
2727
CLArgs.push_back(ArgV[I++]);
@@ -39,7 +39,7 @@ void llvm::handleExecNameEncodedBEOpts(StringRef ExecName) {
3939
SmallVector<StringRef, 4> Opts;
4040
NameAndArgs.second.split(Opts, '-');
4141
for (StringRef Opt : Opts) {
42-
if (Opt.equals("gisel")) {
42+
if (Opt == "gisel") {
4343
Args.push_back("-global-isel");
4444
// For now we default GlobalISel to -O0
4545
Args.push_back("-O0");
@@ -151,7 +151,7 @@ int llvm::runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
151151
for (int I = 1; I < ArgC; ++I) {
152152
StringRef Arg(ArgV[I]);
153153
if (Arg.starts_with("-")) {
154-
if (Arg.equals("-ignore_remaining_args=1"))
154+
if (Arg == "-ignore_remaining_args=1")
155155
break;
156156
continue;
157157
}

llvm/lib/LTO/LTOModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ bool LTOModule::hasCtorDtor() const {
694694
if (auto *GV = dyn_cast_if_present<GlobalValue *>(Sym)) {
695695
StringRef Name = GV->getName();
696696
if (Name.consume_front("llvm.global_")) {
697-
if (Name.equals("ctors") || Name.equals("dtors"))
697+
if (Name == "ctors" || Name == "dtors")
698698
return true;
699699
}
700700
}

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
468468

469469
void MCAsmStreamer::addExplicitComment(const Twine &T) {
470470
StringRef c = T.getSingleStringRef();
471-
if (c.equals(StringRef(MAI->getSeparatorString())))
471+
if (c == MAI->getSeparatorString())
472472
return;
473473
if (c.starts_with(StringRef("//"))) {
474474
ExplicitCommentToEmit.append("\t");

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4543,7 +4543,7 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
45434543

45444544
// Emit an error if two (or more) named parameters share the same name
45454545
for (const MCAsmMacroParameter& CurrParam : Parameters)
4546-
if (CurrParam.Name.equals(Parameter.Name))
4546+
if (CurrParam.Name == Parameter.Name)
45474547
return TokError("macro '" + Name + "' has multiple parameters"
45484548
" named '" + Parameter.Name + "'");
45494549

llvm/lib/MC/MCParser/DarwinAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
705705
.Case("__datacoal_nt", "__data")
706706
.Default(Section);
707707

708-
if (!Section.equals(NonCoalSection)) {
708+
if (Section != NonCoalSection) {
709709
StringRef SectionVal(Loc.getPointer());
710710
size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
711711
SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);

llvm/lib/MC/MCSymbolXCOFF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace llvm;
1313
MCSectionXCOFF *MCSymbolXCOFF::getRepresentedCsect() const {
1414
assert(RepresentedCsect &&
1515
"Trying to get csect representation of this symbol but none was set.");
16-
assert(getSymbolTableName().equals(RepresentedCsect->getSymbolTableName()) &&
16+
assert(getSymbolTableName() == RepresentedCsect->getSymbolTableName() &&
1717
"SymbolTableNames need to be the same for this symbol and its csect "
1818
"representation.");
1919
return RepresentedCsect;
@@ -24,7 +24,7 @@ void MCSymbolXCOFF::setRepresentedCsect(MCSectionXCOFF *C) {
2424
assert((!RepresentedCsect || RepresentedCsect == C) &&
2525
"Trying to set a csect that doesn't match the one that this symbol is "
2626
"already mapped to.");
27-
assert(getSymbolTableName().equals(C->getSymbolTableName()) &&
27+
assert(getSymbolTableName() == C->getSymbolTableName() &&
2828
"SymbolTableNames need to be the same for this symbol and its csect "
2929
"representation.");
3030
RepresentedCsect = C;

0 commit comments

Comments
 (0)