-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang] Use llvm::binary_search (NFC) #140216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_std_binary_search_clang
May 16, 2025
Merged
[clang] Use llvm::binary_search (NFC) #140216
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_std_binary_search_clang
May 16, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140216.diff 6 Files Affected:
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index 543ac8ab2ab12..7d0c2d8658f35 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -311,8 +311,7 @@ class AnalyzerOptions {
return AnalyzerConfigCmdFlags;
}();
- return !std::binary_search(AnalyzerConfigCmdFlags.begin(),
- AnalyzerConfigCmdFlags.end(), Name);
+ return !llvm::binary_search(AnalyzerConfigCmdFlags, Name);
}
AnalyzerOptions()
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 20b5352b83a9e..7e32d2084d5ab 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3091,9 +3091,8 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
tok::l_brace))) ||
(FormatTok->Tok.isAnyIdentifier() &&
- std::binary_search(std::begin(FoundationIdentifiers),
- std::end(FoundationIdentifiers),
- FormatTok->TokenText)) ||
+ llvm::binary_search(FoundationIdentifiers,
+ FormatTok->TokenText)) ||
FormatTok->is(TT_ObjCStringLiteral) ||
FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
Keywords.kw_NS_ERROR_ENUM,
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 1d49d787f9cc9..e0867f6dcce06 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -45,8 +45,7 @@ bool FormatToken::isTypeName(const LangOptions &LangOpts) const {
if (is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts))
return true;
return (LangOpts.CXXOperatorNames || LangOpts.C11) && is(tok::identifier) &&
- std::binary_search(CppNonKeywordTypes.begin(),
- CppNonKeywordTypes.end(), TokenText);
+ llvm::binary_search(CppNonKeywordTypes, TokenText);
}
bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const {
diff --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp
index b11806637efda..3b120abbc3a7a 100644
--- a/clang/lib/Frontend/DiagnosticRenderer.cpp
+++ b/clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -272,8 +272,7 @@ retrieveMacroLocation(SourceLocation Loc, FileID MacroFileID,
if (SM->isMacroArgExpansion(Loc)) {
// Only look at the immediate spelling location of this macro argument if
// the other location in the source range is also present in that expansion.
- if (std::binary_search(CommonArgExpansions.begin(),
- CommonArgExpansions.end(), MacroFileID))
+ if (llvm::binary_search(CommonArgExpansions, MacroFileID))
MacroRange =
CharSourceRange(SM->getImmediateSpellingLoc(Loc), IsTokenRange);
MacroArgRange = SM->getImmediateExpansionRange(Loc);
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 6de19d689988e..89fda3e839cb9 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -482,7 +482,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
// What's left in DToken is the actual prefix. That might not be a -verify
// prefix even if there is only one -verify prefix (for example, the full
// DToken is foo-bar-warning, but foo is the only -verify prefix).
- if (!std::binary_search(Prefixes.begin(), Prefixes.end(), DToken))
+ if (!llvm::binary_search(Prefixes, DToken))
continue;
if (NoDiag) {
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index c2bab9118234c..b2a8459d6b9cc 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -148,8 +148,7 @@ static bool isFeatureTestMacro(StringRef MacroName) {
"__STDCPP_WANT_MATH_SPEC_FUNCS__",
"__STDC_FORMAT_MACROS",
};
- return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
- MacroName);
+ return llvm::binary_search(ReservedMacro, MacroName);
}
static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
|
@llvm/pr-subscribers-clang-format Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140216.diff 6 Files Affected:
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index 543ac8ab2ab12..7d0c2d8658f35 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -311,8 +311,7 @@ class AnalyzerOptions {
return AnalyzerConfigCmdFlags;
}();
- return !std::binary_search(AnalyzerConfigCmdFlags.begin(),
- AnalyzerConfigCmdFlags.end(), Name);
+ return !llvm::binary_search(AnalyzerConfigCmdFlags, Name);
}
AnalyzerOptions()
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 20b5352b83a9e..7e32d2084d5ab 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3091,9 +3091,8 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
tok::l_brace))) ||
(FormatTok->Tok.isAnyIdentifier() &&
- std::binary_search(std::begin(FoundationIdentifiers),
- std::end(FoundationIdentifiers),
- FormatTok->TokenText)) ||
+ llvm::binary_search(FoundationIdentifiers,
+ FormatTok->TokenText)) ||
FormatTok->is(TT_ObjCStringLiteral) ||
FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
Keywords.kw_NS_ERROR_ENUM,
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 1d49d787f9cc9..e0867f6dcce06 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -45,8 +45,7 @@ bool FormatToken::isTypeName(const LangOptions &LangOpts) const {
if (is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts))
return true;
return (LangOpts.CXXOperatorNames || LangOpts.C11) && is(tok::identifier) &&
- std::binary_search(CppNonKeywordTypes.begin(),
- CppNonKeywordTypes.end(), TokenText);
+ llvm::binary_search(CppNonKeywordTypes, TokenText);
}
bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const {
diff --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp
index b11806637efda..3b120abbc3a7a 100644
--- a/clang/lib/Frontend/DiagnosticRenderer.cpp
+++ b/clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -272,8 +272,7 @@ retrieveMacroLocation(SourceLocation Loc, FileID MacroFileID,
if (SM->isMacroArgExpansion(Loc)) {
// Only look at the immediate spelling location of this macro argument if
// the other location in the source range is also present in that expansion.
- if (std::binary_search(CommonArgExpansions.begin(),
- CommonArgExpansions.end(), MacroFileID))
+ if (llvm::binary_search(CommonArgExpansions, MacroFileID))
MacroRange =
CharSourceRange(SM->getImmediateSpellingLoc(Loc), IsTokenRange);
MacroArgRange = SM->getImmediateExpansionRange(Loc);
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 6de19d689988e..89fda3e839cb9 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -482,7 +482,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
// What's left in DToken is the actual prefix. That might not be a -verify
// prefix even if there is only one -verify prefix (for example, the full
// DToken is foo-bar-warning, but foo is the only -verify prefix).
- if (!std::binary_search(Prefixes.begin(), Prefixes.end(), DToken))
+ if (!llvm::binary_search(Prefixes, DToken))
continue;
if (NoDiag) {
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index c2bab9118234c..b2a8459d6b9cc 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -148,8 +148,7 @@ static bool isFeatureTestMacro(StringRef MacroName) {
"__STDCPP_WANT_MATH_SPEC_FUNCS__",
"__STDC_FORMAT_MACROS",
};
- return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
- MacroName);
+ return llvm::binary_search(ReservedMacro, MacroName);
}
static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
|
arsenm
approved these changes
May 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang:static analyzer
clang
Clang issues not falling into any other category
clang-format
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.