[clang-tidy] Use early returns to make the code easier to read and potentially run faster

This commit is contained in:
Alexander Kornienko 2019-12-12 16:51:08 +01:00
parent 2b09390c13
commit 65996c302a
1 changed files with 5 additions and 6 deletions

View File

@ -262,26 +262,25 @@ static bool matchesStyle(StringRef Name,
llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"), llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
}; };
bool Matches = true;
if (Name.startswith(Style.Prefix)) if (Name.startswith(Style.Prefix))
Name = Name.drop_front(Style.Prefix.size()); Name = Name.drop_front(Style.Prefix.size());
else else
Matches = false; return false;
if (Name.endswith(Style.Suffix)) if (Name.endswith(Style.Suffix))
Name = Name.drop_back(Style.Suffix.size()); Name = Name.drop_back(Style.Suffix.size());
else else
Matches = false; return false;
// Ensure the name doesn't have any extra underscores beyond those specified // Ensure the name doesn't have any extra underscores beyond those specified
// in the prefix and suffix. // in the prefix and suffix.
if (Name.startswith("_") || Name.endswith("_")) if (Name.startswith("_") || Name.endswith("_"))
Matches = false; return false;
if (Style.Case && !Matchers[static_cast<size_t>(*Style.Case)].match(Name)) if (Style.Case && !Matchers[static_cast<size_t>(*Style.Case)].match(Name))
Matches = false; return false;
return Matches; return true;
} }
static std::string fixupWithCase(StringRef Name, static std::string fixupWithCase(StringRef Name,