[clang-tools-extra] 1da76b4 - [clangd][NFC] Make some local variables HeaderSourceSwitch.cpp const and constexpr (#143193)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 2 21:23:22 PDT 2025
Author: Jouni
Date: 2025-08-03T00:23:19-04:00
New Revision: 1da76b42ae437235a6be2c75d91b8d4e04a6d1da
URL: https://github.com/llvm/llvm-project/commit/1da76b42ae437235a6be2c75d91b8d4e04a6d1da
DIFF: https://github.com/llvm/llvm-project/commit/1da76b42ae437235a6be2c75d91b8d4e04a6d1da.diff
LOG: [clangd][NFC] Make some local variables HeaderSourceSwitch.cpp const and constexpr (#143193)
Added:
Modified:
clang-tools-extra/clangd/HeaderSourceSwitch.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
index d54c3668570eb..ee4bea1401490 100644
--- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
+++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
@@ -20,22 +20,24 @@ namespace clangd {
std::optional<Path> getCorrespondingHeaderOrSource(
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
- llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
- ".c++", ".m", ".mm"};
- llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx",
- ".inc", ".cppm", ".ccm", ".cxxm",
- ".c++m", ".ixx"};
+ static constexpr llvm::StringRef SourceExtensions[] = {
+ ".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"};
+ static constexpr llvm::StringRef HeaderExtensions[] = {
+ ".h", ".hh", ".hpp", ".hxx", ".inc",
+ ".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"};
llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);
// Lookup in a list of known extensions.
- bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
- return SourceExt.equals_insensitive(PathExt);
- });
+ const bool IsSource =
+ llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
+ return SourceExt.equals_insensitive(PathExt);
+ });
- bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
- return HeaderExt.equals_insensitive(PathExt);
- });
+ const bool IsHeader =
+ llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
+ return HeaderExt.equals_insensitive(PathExt);
+ });
// We can only switch between the known extensions.
if (!IsSource && !IsHeader)
@@ -94,7 +96,7 @@ std::optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
//
// For each symbol in the original file, we get its target location (decl or
// def) from the index, then award that target file.
- bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
+ const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
Index->lookup(Request, [&](const Symbol &Sym) {
if (IsHeader)
AwardTarget(Sym.Definition.FileURI);
More information about the cfe-commits
mailing list