Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalPage.cpp (C++)

Code before:
        // Give term control a child of the settings so that any overrides go in the child
        // This way, when we do a settings reload we just update the parent and the overrides remain
        const auto child = TerminalSettings::CreateWithParent(settings);
        TermControl term{ child.DefaultSettings(), connection };

        term.UnfocusedAppearance(child.UnfocusedSettings()); // It is okay for the unfocused settings to be null

        return term;
    }

    // Method Description:
    // - Hook up keybindings, and refresh the UI of the terminal.
    //   This includes update the settings of all the tabs according
    //   to their profiles, update the title and icon of each tab, and
    //   finally create the tab flyout
    void TerminalPage::_RefreshUIForSettingsReload()
    {
        // Re-wire the keybindings to their handlers, as we'll have created a
        // new AppKeyBindings object.
        _HookupKeyBindings(_settings.ActionMap());

        // Refresh UI elements

        // Mapping by GUID isn't _excellent_ because the defaults profile doesn't have a stable GUID; however,
        // when we stabilize its guid this will become fully safe.
        std::unordered_map<winrt::guid, std::pair<Profile, TerminalSettingsCreateResult>> _profileGuidSettingsMap;

        // Include the Defaults profile for consideration
        const auto profileDefaults{ _settings.ProfileDefaults() };
        _profileGuidSettingsMap.insert_or_assign(profileDefaults.Guid(), std::pair{ profileDefaults, nullptr });
        for (const auto& newProfile : _settings.AllProfiles())
        {
            // Avoid creating a TerminalSettings right now. They're not totally cheap, and we suspect that users with many
            // panes may not be using all of their profiles at the same time. Lazy evaluation is king!
            _profileGuidSettingsMap.insert_or_assign(newProfile.Guid(), std::pair{ newProfile, nullptr });
        }

        for (const auto& tab : _tabs)
        {
            if (auto terminalTab{ _GetTerminalTabImpl(tab) })
            {
                terminalTab->UpdateSettings();

                // Manually enumerate the panes in each tab; this will let us recycle TerminalSettings
                // objects but only have to iterate one time.
                terminalTab->GetRootPane()->WalkTree([&](auto&& pane) {
                    if (const auto profile{ pane->GetProfile() })
                    {
                        const auto found{ _profileGuidSettingsMap.find(profile.Guid()) };
                        // GH#2455: If there are any panes with controls that had been
                        // initialized with a Profile that no longer exists in our list of

Review comment (bug):
Remove the underscore here - it's a local variable right?

_If_ you want to you can also do:
```cpp
const auto profileDefaults{ _settings.ProfileDefaults() };
const auto allProfiles{ _settings.AllProfiles() };

std::unordered_map<winrt::guid, std::pair<Profile, TerminalSettingsCreateResult>> profileGuidSettingsMap;
profileGuidSettingsMap.reserve(allProfiles.Size() + 1); // <------------------ reserve

// Abstract away insert_or_assign? Just an idea ¯\_(ツ)_/¯
static constexpr auto add = [](auto& map, const auto& profile) {
	map.insert_or_assign(profile.Guid(), std::pair{ profile, nullptr });
};

add(profileGuidSettingsMap, profileDefaults);
for (const auto& newProfile : allProfiles)
{
    // Avoid creating a TerminalSettings right now. They're not totally cheap, and we suspect that users with many
    // panes may not be using all of their profiles at the same time. Lazy evaluation is king!
    add(profileGuidSettingsMap, newProfile);
}
```

Code after:
        // Give term control a child of the settings so that any overrides go in the child
        // This way, when we do a settings reload we just update the parent and the overrides remain
        const auto child = TerminalSettings::CreateWithParent(settings);
        TermControl term{ child.DefaultSettings(), connection };

        term.UnfocusedAppearance(child.UnfocusedSettings()); // It is okay for the unfocused settings to be null

        return term;
    }

    // Method Description:
    // - Hook up keybindings, and refresh the UI of the terminal.
    //   This includes update the settings of all the tabs according
    //   to their profiles, update the title and icon of each tab, and
    //   finally create the tab flyout
    void TerminalPage::_RefreshUIForSettingsReload()
    {
        // Re-wire the keybindings to their handlers, as we'll have created a
        // new AppKeyBindings object.
        _HookupKeyBindings(_settings.ActionMap());

        // Refresh UI elements

        // Mapping by GUID isn't _excellent_ because the defaults profile doesn't have a stable GUID; however,
        // when we stabilize its guid this will become fully safe.
        std::unordered_map<winrt::guid, std::pair<Profile, TerminalSettingsCreateResult>> profileGuidSettingsMap;
        const auto profileDefaults{ _settings.ProfileDefaults() };
        const auto allProfiles{ _settings.AllProfiles() };

        profileGuidSettingsMap.reserve(allProfiles.Size() + 1);

        // Include the Defaults profile for consideration
        profileGuidSettingsMap.insert_or_assign(profileDefaults.Guid(), std::pair{ profileDefaults, nullptr });
        for (const auto& newProfile : allProfiles)
        {
            // Avoid creating a TerminalSettings right now. They're not totally cheap, and we suspect that users with many
            // panes may not be using all of their profiles at the same time. Lazy evaluation is king!
            profileGuidSettingsMap.insert_or_assign(newProfile.Guid(), std::pair{ newProfile, nullptr });
        }

        for (const auto& tab : _tabs)
        {
            if (auto terminalTab{ _GetTerminalTabImpl(tab) })
            {
                terminalTab->UpdateSettings();

                // Manually enumerate the panes in each tab; this will let us recycle TerminalSettings
                // objects but only have to iterate one time.
                terminalTab->GetRootPane()->WalkTree([&](auto&& pane) {
                    if (const auto profile{ pane->GetProfile() })
                    {