diff options
author | Jouni <dz4tune@gmail.com> | 2025-08-03 06:23:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-03 00:23:19 -0400 |
commit | 1da76b42ae437235a6be2c75d91b8d4e04a6d1da (patch) | |
tree | 15be3e46f29991721969078aa7e9c9caaf2f208f | |
parent | 7de0da40c0938e1ea7c11a672ae5a329dcf92def (diff) | |
download | llvm-1da76b42ae437235a6be2c75d91b8d4e04a6d1da.zip llvm-1da76b42ae437235a6be2c75d91b8d4e04a6d1da.tar.gz llvm-1da76b42ae437235a6be2c75d91b8d4e04a6d1da.tar.bz2 |
[clangd][NFC] Make some local variables HeaderSourceSwitch.cpp const and constexpr (#143193)
-rw-r--r-- | clang-tools-extra/clangd/HeaderSourceSwitch.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp index d54c366..ee4bea1 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); |