Use StringRef::contains (NFC)

This commit is contained in:
Kazu Hirata 2022-08-28 23:29:02 -07:00
parent 0e9d37ff95
commit 20f0f15a40
6 changed files with 8 additions and 11 deletions

View File

@ -449,7 +449,7 @@ protected:
bool usesEvent(StringRef Name) const {
for (auto I = EventNames.begin(), E = EventNames.end(); I != E; ++I) {
StringRef Event = I->getKey();
if (Event.find(Name) != StringRef::npos)
if (Event.contains(Name))
return true;
}
return false;

View File

@ -1158,7 +1158,7 @@ ErrorOr<DataAggregator::PerfMemSample> DataAggregator::parseMemSample() {
ErrorOr<StringRef> Event = parseString(FieldSeparator);
if (std::error_code EC = Event.getError())
return EC;
if (Event.get().find("mem-loads") == StringRef::npos) {
if (!Event.get().contains("mem-loads")) {
consumeRestOfLine();
return Res;
}

View File

@ -206,7 +206,7 @@ std::string getShortestQualifiedNameInNamespace(llvm::StringRef DeclName,
llvm::StringRef NsName) {
DeclName = DeclName.ltrim(':');
NsName = NsName.ltrim(':');
if (DeclName.find(':') == llvm::StringRef::npos)
if (!DeclName.contains(':'))
return std::string(DeclName);
auto NsNameSplitted = splitSymbolName(NsName);

View File

@ -68,9 +68,8 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
PtrToContainer = true;
}
const llvm::StringRef IneffContName = IneffCont->getName();
const bool Unordered =
IneffContName.find("unordered") != llvm::StringRef::npos;
const bool Maplike = IneffContName.find("map") != llvm::StringRef::npos;
const bool Unordered = IneffContName.contains("unordered");
const bool Maplike = IneffContName.contains("map");
// Store if the key type of the container is compatible with the value
// that is searched for.
@ -84,8 +83,7 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
const Expr *Arg = AlgCall->getArg(3);
const QualType AlgCmp =
Arg->getType().getUnqualifiedType().getCanonicalType();
const unsigned CmpPosition =
(IneffContName.find("map") == llvm::StringRef::npos) ? 1 : 2;
const unsigned CmpPosition = IneffContName.contains("map") ? 2 : 1;
const QualType ContainerCmp = IneffCont->getTemplateArgs()[CmpPosition]
.getAsType()
.getUnqualifiedType()

View File

@ -1497,7 +1497,7 @@ public:
/// NaN strings as well. \p s is assumed to not contain any spaces.
static llvm::APFloat consAPFloat(const llvm::fltSemantics &fsem,
llvm::StringRef s) {
assert(s.find(' ') == llvm::StringRef::npos);
assert(!s.contains(' '));
if (s.compare_insensitive("-inf") == 0)
return llvm::APFloat::getInf(fsem, /*negative=*/true);
if (s.compare_insensitive("inf") == 0 || s.compare_insensitive("+inf") == 0)

View File

@ -1417,8 +1417,7 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter,
mlir::Value stringRef;
mlir::Value stringLen;
if (eval->isA<Fortran::parser::FormatStmt>()) {
assert(text.find('(') != llvm::StringRef::npos &&
"FORMAT is unexpectedly ill-formed");
assert(text.contains('(') && "FORMAT is unexpectedly ill-formed");
// This is a format statement, so extract the spec from the text.
std::tuple<mlir::Value, mlir::Value, mlir::Value> stringLit =
lowerSourceTextAsStringLit(converter, loc, text, strTy, lenTy);