Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/ActionMap.cpp (C++)

Code before:
        std::filesystem::path directory{ std::wstring_view{ currentWorkingDirectory } };
        std::vector<std::filesystem::path> directories;
        while (!directory.empty())
        {
            directories.push_back(directory);
            const auto parentPath = directory.parent_path();
            if (directory == parentPath)
            {
                break;
            }
            directory = parentPath;
        }

        {
            // Check if all the directories are already in the cache
            const auto& cache{ _cwdLocalSnippetsCache.lock_shared() };

            bool allSnippetsCached = true;
            for (const auto& dir : directories)
            {
                if (!cache->contains(dir))
                {
                    allSnippetsCached = false;
                    break;
                }
            }
            if (allSnippetsCached)
            {
                // Load snippets from directories in reverse order.
                // This ensures that we prioritize snippets closer to the cwd.
                // The map makes it easy to avoid duplicates.
                std::unordered_map<hstring, Model::Command> localSnippetsMap;
                for (decltype(directories)::reverse_iterator rit = directories.rbegin(); rit != directories.rend(); ++rit)
                {
                    // register snippets from cache
                    std::ranges::for_each(cache->at(*rit), [&localSnippetsMap](const auto& kvPair) {
                        localSnippetsMap.insert_or_assign(kvPair.first, kvPair.second);
                    });
                }

                std::vector<Model::Command> localSnippets;
                localSnippets.reserve(localSnippetsMap.size());
                std::ranges::transform(localSnippetsMap,
                                       std::back_inserter(localSnippets),
                                       [](const auto& kvPair) { return kvPair.second; });
                co_return winrt::single_threaded_vector<Model::Command>(_filterToSnippets(NameMap(),
                                                                                          currentCommandline,
                                                                                          localSnippets));
            }
        } // release the lock on the cache


Review comment (performance):
Could use this here:
```cpp
std::ranges::all_of(directories, [&](const auto& dir) {
    return cache->contains(dir);
})
```

Look it's a one-liner!
```cpp
if (std::ranges::all_of(directories, [&](auto&& dir) { return cache->contains(dir); }))
```

Code after:
        std::filesystem::path directory{ std::wstring_view{ currentWorkingDirectory } };
        std::vector<std::filesystem::path> directories;
        while (!directory.empty())
        {
            directories.push_back(directory);
            auto parentPath = directory.parent_path();
            if (directory == parentPath)
            {
                break;
            }
            directory = std::move(parentPath);
        }

        {
            // Check if all the directories are already in the cache
            const auto& cache{ _cwdLocalSnippetsCache.lock_shared() };
            if (std::ranges::all_of(directories, [&](auto&& dir) { return cache->contains(dir); }))
            {
                // Load snippets from directories in reverse order.
                // This ensures that we prioritize snippets closer to the cwd.
                // The map makes it easy to avoid duplicates.
                std::unordered_map<hstring, Model::Command> localSnippetsMap;
                for (auto rit = directories.rbegin(); rit != directories.rend(); ++rit)
                {
                    // register snippets from cache
                    for (const auto& [name, snippet] : cache->at(*rit))
                    {
                        localSnippetsMap.insert_or_assign(name, snippet);
                    }
                }

                std::vector<Model::Command> localSnippets;
                localSnippets.reserve(localSnippetsMap.size());
                std::ranges::transform(localSnippetsMap,
                                       std::back_inserter(localSnippets),
                                       [](const auto& kvPair) { return kvPair.second; });
                co_return winrt::single_threaded_vector<Model::Command>(_filterToSnippets(NameMap(),
                                                                                          currentCommandline,
                                                                                          localSnippets));
            }
        } // release the lock on the cache

        // Don't do I/O on the main thread
        co_await winrt::resume_background();

        // Load snippets from directories in reverse order.
        // This ensures that we prioritize snippets closer to the cwd.
        // The map makes it easy to avoid duplicates.
        const auto& cache{ _cwdLocalSnippetsCache.lock() };
        std::unordered_map<hstring, Model::Command> localSnippetsMap;
        for (auto rit = directories.rbegin(); rit != directories.rend(); ++rit)