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

View File

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

View File

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

View File

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

View File

@ -1497,7 +1497,7 @@ public:
/// NaN strings as well. \p s is assumed to not contain any spaces. /// NaN strings as well. \p s is assumed to not contain any spaces.
static llvm::APFloat consAPFloat(const llvm::fltSemantics &fsem, static llvm::APFloat consAPFloat(const llvm::fltSemantics &fsem,
llvm::StringRef s) { llvm::StringRef s) {
assert(s.find(' ') == llvm::StringRef::npos); assert(!s.contains(' '));
if (s.compare_insensitive("-inf") == 0) if (s.compare_insensitive("-inf") == 0)
return llvm::APFloat::getInf(fsem, /*negative=*/true); return llvm::APFloat::getInf(fsem, /*negative=*/true);
if (s.compare_insensitive("inf") == 0 || s.compare_insensitive("+inf") == 0) 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 stringRef;
mlir::Value stringLen; mlir::Value stringLen;
if (eval->isA<Fortran::parser::FormatStmt>()) { if (eval->isA<Fortran::parser::FormatStmt>()) {
assert(text.find('(') != llvm::StringRef::npos && assert(text.contains('(') && "FORMAT is unexpectedly ill-formed");
"FORMAT is unexpectedly ill-formed");
// This is a format statement, so extract the spec from the text. // This is a format statement, so extract the spec from the text.
std::tuple<mlir::Value, mlir::Value, mlir::Value> stringLit = std::tuple<mlir::Value, mlir::Value, mlir::Value> stringLit =
lowerSourceTextAsStringLit(converter, loc, text, strTy, lenTy); lowerSourceTextAsStringLit(converter, loc, text, strTy, lenTy);