Skip to content

Commit

Permalink
Use StringRef::contains (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Aug 29, 2022
1 parent 0e9d37f commit 20f0f15
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bolt/include/bolt/Profile/DataReader.h
Expand Up @@ -449,7 +449,7 @@ class DataReader : public ProfileReaderBase {
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;
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Profile/DataAggregator.cpp
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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.
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/ConvertExpr.cpp
Expand Up @@ -1497,7 +1497,7 @@ class ScalarExprLowering {
/// 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)
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Lower/IO.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 20f0f15

Please sign in to comment.