[clang-tools-extra] [clang-tidy][NFC] optimize cache for config option (PR #121406)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 14:06:52 PST 2025
================
@@ -337,33 +337,34 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
void FileOptionsBaseProvider::addRawFileOptions(
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
auto CurSize = CurOptions.size();
-
// Look for a suitable configuration file in all parent directories of the
// file. Start with the immediate parent directory and move up.
- StringRef Path = llvm::sys::path::parent_path(AbsolutePath);
- for (StringRef CurrentPath = Path; !CurrentPath.empty();
- CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
- std::optional<OptionsSource> Result;
-
- auto Iter = CachedOptions.find(CurrentPath);
- if (Iter != CachedOptions.end())
- Result = Iter->second;
-
- if (!Result)
- Result = tryReadConfigFile(CurrentPath);
-
- if (Result) {
- // Store cached value for all intermediate directories.
- while (Path != CurrentPath) {
+ StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
+ auto MemorizedConfigFile =
+ [this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
+ auto Iter = CachedOptions.Memorized.find(CurrentPath);
----------------
5chmidti wrote:
nit: can be `const`, and can be declared as the if-init var to reduce its scope
https://github.com/llvm/llvm-project/pull/121406
More information about the cfe-commits
mailing list