Skip to content

[Support] Use StringRef::operator== instead of StringRef::equals (NFC) #91042

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

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/VirtualFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ class RedirectingFileSystem
// that, other than the root, path components should not contain slashes or
// backslashes.
bool pathComponentMatches(llvm::StringRef lhs, llvm::StringRef rhs) const {
if ((CaseSensitive ? lhs.equals(rhs) : lhs.equals_insensitive(rhs)))
if ((CaseSensitive ? lhs == rhs : lhs.equals_insensitive(rhs)))
return true;
return (lhs == "/" && rhs == "\\") || (lhs == "\\" && rhs == "/");
}
Expand Down
15 changes: 7 additions & 8 deletions llvm/include/llvm/Support/YAMLTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,18 +567,18 @@ inline bool isNumeric(StringRef S) {

// Make S.front() and S.drop_front().front() (if S.front() is [+-]) calls
// safe.
if (S.empty() || S.equals("+") || S.equals("-"))
if (S.empty() || S == "+" || S == "-")
return false;

if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
if (S == ".nan" || S == ".NaN" || S == ".NAN")
return true;

// Infinity and decimal numbers can be prefixed with sign.
StringRef Tail = (S.front() == '-' || S.front() == '+') ? S.drop_front() : S;

// Check for infinity first, because checking for hex and oct numbers is more
// expensive.
if (Tail.equals(".inf") || Tail.equals(".Inf") || Tail.equals(".INF"))
if (Tail == ".inf" || Tail == ".Inf" || Tail == ".INF")
return true;

// Section 10.3.2 Tag Resolution
Expand All @@ -599,7 +599,7 @@ inline bool isNumeric(StringRef S) {
// digit after dot (as opposed by number which has digits before the dot), but
// doesn't have one.
if (S.starts_with(".") &&
(S.equals(".") ||
(S == "." ||
(S.size() > 1 && std::strchr("0123456789", S[1]) == nullptr)))
return false;

Expand Down Expand Up @@ -656,14 +656,13 @@ inline bool isNumeric(StringRef S) {
}

inline bool isNull(StringRef S) {
return S.equals("null") || S.equals("Null") || S.equals("NULL") ||
S.equals("~");
return S == "null" || S == "Null" || S == "NULL" || S == "~";
}

inline bool isBool(StringRef S) {
// FIXME: using parseBool is causing multiple tests to fail.
return S.equals("true") || S.equals("True") || S.equals("TRUE") ||
S.equals("false") || S.equals("False") || S.equals("FALSE");
return S == "true" || S == "True" || S == "TRUE" || S == "false" ||
S == "False" || S == "FALSE";
}

// 5.1. Character Set
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/APFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ bool IEEEFloat::convertFromStringSpecials(StringRef str) {
if (str.size() < MIN_NAME_SIZE)
return false;

if (str.equals("inf") || str.equals("INFINITY") || str.equals("+Inf")) {
if (str == "inf" || str == "INFINITY" || str == "+Inf") {
makeInf(false);
return true;
}
Expand All @@ -3134,7 +3134,7 @@ bool IEEEFloat::convertFromStringSpecials(StringRef str) {
if (str.size() < MIN_NAME_SIZE)
return false;

if (str.equals("inf") || str.equals("INFINITY") || str.equals("Inf")) {
if (str == "inf" || str == "INFINITY" || str == "Inf") {
makeInf(true);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/CodeGenCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool CodeGenCoverage::parse(MemoryBuffer &Buffer, StringRef BackendName) {
if (CurPtr == Buffer.getBufferEnd())
return false; // Data is invalid, expected rule id's to follow.

bool IsForThisBackend = BackendName.equals(LexedBackendName);
bool IsForThisBackend = BackendName == LexedBackendName;
while (CurPtr != Buffer.getBufferEnd()) {
if (std::distance(CurPtr, Buffer.getBufferEnd()) < 8)
return false; // Data is invalid. Not enough bytes for another rule id.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/FileCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static bool isCaseSensitivePath(StringRef Path) {
// sensitive in the absence of real_path, since this is the YAMLVFSWriter
// default.
UpperDest = Path.upper();
if (!sys::fs::real_path(UpperDest, RealDest) && Path.equals(RealDest))
if (!sys::fs::real_path(UpperDest, RealDest) && Path == RealDest)
return false;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void Path::Root::printErrorContext(const Value &R, raw_ostream &OS) const {
JOS.object([&] {
for (const auto *KV : sortedElements(*O)) {
JOS.attributeBegin(KV->first);
if (FieldName.equals(KV->first))
if (FieldName == StringRef(KV->first))
Recurse(KV->second, Path.drop_back(), Recurse);
else
abbreviate(KV->second, JOS);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/VirtualFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void FileSystem::dump() const { print(dbgs(), PrintType::RecursiveContents); }

#ifndef NDEBUG
static bool isTraversalComponent(StringRef Component) {
return Component.equals("..") || Component.equals(".");
return Component == ".." || Component == ".";
}

static bool pathHasTraversal(StringRef Path) {
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Support/YAMLTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool Input::mapTag(StringRef Tag, bool Default) {
return Default;
}
// Return true iff found tag matches supplied tag.
return Tag.equals(foundTag);
return Tag == foundTag;
}

void Input::beginMapping() {
Expand Down Expand Up @@ -271,7 +271,7 @@ bool Input::matchEnumScalar(const char *Str, bool) {
if (ScalarMatchFound)
return false;
if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) {
if (SN->value().equals(Str)) {
if (SN->value() == Str) {
ScalarMatchFound = true;
return true;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ bool Input::bitSetMatch(const char *Str, bool) {
unsigned Index = 0;
for (auto &N : SQ->Entries) {
if (ScalarHNode *SN = dyn_cast<ScalarHNode>(N)) {
if (SN->value().equals(Str)) {
if (SN->value() == Str) {
BitValuesUsed[Index] = true;
return true;
}
Expand Down