Skip to content

Commit 1da76b4

Browse files
authored
[clangd][NFC] Make some local variables HeaderSourceSwitch.cpp const and constexpr (llvm#143193)
1 parent 7de0da4 commit 1da76b4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

clang-tools-extra/clangd/HeaderSourceSwitch.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,24 @@ namespace clangd {
2020

2121
std::optional<Path> getCorrespondingHeaderOrSource(
2222
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
23-
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
24-
".c++", ".m", ".mm"};
25-
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx",
26-
".inc", ".cppm", ".ccm", ".cxxm",
27-
".c++m", ".ixx"};
23+
static constexpr llvm::StringRef SourceExtensions[] = {
24+
".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"};
25+
static constexpr llvm::StringRef HeaderExtensions[] = {
26+
".h", ".hh", ".hpp", ".hxx", ".inc",
27+
".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"};
2828

2929
llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);
3030

3131
// Lookup in a list of known extensions.
32-
bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
33-
return SourceExt.equals_insensitive(PathExt);
34-
});
32+
const bool IsSource =
33+
llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
34+
return SourceExt.equals_insensitive(PathExt);
35+
});
3536

36-
bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
37-
return HeaderExt.equals_insensitive(PathExt);
38-
});
37+
const bool IsHeader =
38+
llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
39+
return HeaderExt.equals_insensitive(PathExt);
40+
});
3941

4042
// We can only switch between the known extensions.
4143
if (!IsSource && !IsHeader)
@@ -94,7 +96,7 @@ std::optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
9496
//
9597
// For each symbol in the original file, we get its target ___location (decl or
9698
// def) from the index, then award that target file.
97-
bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
99+
const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
98100
Index->lookup(Request, [&](const Symbol &Sym) {
99101
if (IsHeader)
100102
AwardTarget(Sym.Definition.FileURI);

0 commit comments

Comments
 (0)