Skip to content

Commit

Permalink
[clang] Use StringRef::consume_front (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Dec 25, 2023
1 parent 9e98f8d commit 68f832f
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 21 deletions.
3 changes: 1 addition & 2 deletions clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {

// Strip off a leading diagnostic code if there is one.
StringRef Msg = Err.getMessage();
if (Msg.starts_with("error: "))
Msg = Msg.substr(7);
Msg.consume_front("error: ");

unsigned DiagID =
CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,8 +2388,7 @@ static void GetSDLFromOffloadArchive(
FoundAOB = true;
}
} else {
if (Lib.starts_with("-l"))
Lib = Lib.drop_front(2);
Lib.consume_front("-l");
for (auto LPath : LibraryPaths) {
ArchiveOfBundles.clear();
auto LibFile = (Lib.starts_with(":") ? Lib.drop_front()
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Frontend/DependencyGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ void DependencyGraphCallback::OutputGraphFile() {
writeNodeReference(OS, AllFiles[I]);
OS << " [ shape=\"box\", label=\"";
StringRef FileName = AllFiles[I].getName();
if (FileName.starts_with(SysRoot))
FileName = FileName.substr(SysRoot.size());
FileName.consume_front(SysRoot);

OS << DOT::EscapeString(std::string(FileName)) << "\"];\n";
}
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,7 @@ std::unique_ptr<Directive> Directive::create(bool RegexKind,
std::string RegexStr;
StringRef S = Text;
while (!S.empty()) {
if (S.starts_with("{{")) {
S = S.drop_front(2);
if (S.consume_front("{{")) {
size_t RegexMatchLength = S.find("}}");
assert(RegexMatchLength != StringRef::npos);
// Append the regex, enclosed in parentheses.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,8 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
if (IsChkVariant) {
FunctionName = FunctionName.drop_front(std::strlen("__builtin___"));
FunctionName = FunctionName.drop_back(std::strlen("_chk"));
} else if (FunctionName.starts_with("__builtin_")) {
FunctionName = FunctionName.drop_front(std::strlen("__builtin_"));
} else {
FunctionName.consume_front("__builtin_");
}
return FunctionName;
};
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5825,8 +5825,7 @@ struct IntrinToName {
static bool ArmBuiltinAliasValid(unsigned BuiltinID, StringRef AliasName,
ArrayRef<IntrinToName> Map,
const char *IntrinNames) {
if (AliasName.starts_with("__arm_"))
AliasName = AliasName.substr(6);
AliasName.consume_front("__arm_");
const IntrinToName *It =
llvm::lower_bound(Map, BuiltinID, [](const IntrinToName &L, unsigned Id) {
return L.Id < Id;
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
if (!II) // if no identifier, not a simple C function
return;
StringRef Name = II->getName();
if (Name.starts_with("__builtin_"))
Name = Name.substr(10);
Name.consume_front("__builtin_");

// Set the evaluation function by switching on the callee name.
FnCheck evalFunction =
Expand Down Expand Up @@ -763,8 +762,7 @@ void WalkAST::checkDeprecatedOrUnsafeBufferHandling(const CallExpr *CE,
enum { DEPR_ONLY = -1, UNKNOWN_CALL = -2 };

StringRef Name = FD->getIdentifier()->getName();
if (Name.starts_with("__builtin_"))
Name = Name.substr(10);
Name.consume_front("__builtin_");

int ArgIndex =
llvm::StringSwitch<int>(Name)
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Tooling/Refactoring/Lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ static StringRef getBestNamespaceSubstr(const DeclContext *DeclA,
// from NewName if it has an identical prefix.
std::string NS =
"::" + cast<NamespaceDecl>(DeclA)->getQualifiedNameAsString() + "::";
if (NewName.starts_with(NS))
return NewName.substr(NS.size());
if (NewName.consume_front(NS))
return NewName;

// No match yet. Strip of a namespace from the end of the chain and try
// again. This allows to get optimal qualifications even if the old and new
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Tooling/Tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ llvm::Expected<std::string> getAbsolutePath(llvm::vfs::FileSystem &FS,
StringRef File) {
StringRef RelativePath(File);
// FIXME: Should '.\\' be accepted on Win32?
if (RelativePath.starts_with("./")) {
RelativePath = RelativePath.substr(strlen("./"));
}
RelativePath.consume_front("./");

SmallString<1024> AbsolutePath = RelativePath;
if (auto EC = FS.makeAbsolute(AbsolutePath))
Expand Down

0 comments on commit 68f832f

Please sign in to comment.