[clang] 26648da - [ExtractAPI] Use StringRef::starts_with (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 28 10:47:14 PST 2024
Author: Kazu Hirata
Date: 2024-01-28T10:47:05-08:00
New Revision: 26648daeb2ea1e9443d214e3923583efba346603
URL: https://github.com/llvm/llvm-project/commit/26648daeb2ea1e9443d214e3923583efba346603
DIFF: https://github.com/llvm/llvm-project/commit/26648daeb2ea1e9443d214e3923583efba346603.diff
LOG: [ExtractAPI] Use StringRef::starts_with (NFC)
Added:
Modified:
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/lib/ExtractAPI/DeclarationFragments.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h b/clang/include/clang/ExtractAPI/DeclarationFragments.h
index 1b78c8b5931e410..b85a5d21d61217e 100644
--- a/clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -429,8 +429,7 @@ DeclarationFragmentsBuilder::getFunctionSignature(const FunctionT *Function) {
Function->getASTContext(), After);
if (isa<FunctionDecl>(Function) &&
dyn_cast<FunctionDecl>(Function)->getDescribedFunctionTemplate() &&
- ReturnType.begin()->Spelling.substr(0, 14).compare("type-parameter") ==
- 0) {
+ StringRef(ReturnType.begin()->Spelling).starts_with("type-parameter")) {
std::string ProperArgName =
getNameForTemplateArgument(dyn_cast<FunctionDecl>(Function)
->getDescribedFunctionTemplate()
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 56c1f5bf5eab068..80a0a498dc40016 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -533,8 +533,8 @@ DeclarationFragmentsBuilder::getFragmentsForVarTemplate(const VarDecl *Var) {
DeclarationFragments After;
DeclarationFragments ArgumentFragment =
getFragmentsForType(T, Var->getASTContext(), After);
- if (ArgumentFragment.begin()->Spelling.substr(0, 14).compare(
- "type-parameter") == 0) {
+ if (StringRef(ArgumentFragment.begin()->Spelling)
+ .starts_with("type-parameter")) {
std::string ProperArgName = getNameForTemplateArgument(
Var->getDescribedVarTemplate()->getTemplateParameters()->asArray(),
ArgumentFragment.begin()->Spelling);
@@ -568,8 +568,8 @@ DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
else
TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
- if (TypeFragments.begin()->Spelling.substr(0, 14).compare("type-parameter") ==
- 0) {
+ if (StringRef(TypeFragments.begin()->Spelling)
+ .starts_with("type-parameter")) {
std::string ProperArgName = getNameForTemplateArgument(
dyn_cast<FunctionDecl>(Param->getDeclContext())
->getDescribedFunctionTemplate()
@@ -666,8 +666,8 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const FunctionDecl *Func) {
DeclarationFragments After;
auto ReturnValueFragment =
getFragmentsForType(Func->getReturnType(), Func->getASTContext(), After);
- if (ReturnValueFragment.begin()->Spelling.substr(0, 14).compare(
- "type-parameter") == 0) {
+ if (StringRef(ReturnValueFragment.begin()->Spelling)
+ .starts_with("type-parameter")) {
std::string ProperArgName =
getNameForTemplateArgument(Func->getDescribedFunctionTemplate()
->getTemplateParameters()
@@ -1001,8 +1001,8 @@ DeclarationFragmentsBuilder::getFragmentsForTemplateArguments(
DeclarationFragments ArgumentFragment =
getFragmentsForType(TemplateArguments[i].getAsType(), Context, After);
- if (ArgumentFragment.begin()->Spelling.substr(0, 14).compare(
- "type-parameter") == 0) {
+ if (StringRef(ArgumentFragment.begin()->Spelling)
+ .starts_with("type-parameter")) {
std::string ProperArgName = getNameForTemplateArgument(
TemplateParameters.value(), ArgumentFragment.begin()->Spelling);
ArgumentFragment.begin()->Spelling.swap(ProperArgName);
More information about the cfe-commits
mailing list