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

Code before:
        if (lastFocusedProfileOpt.has_value())
        {
            const auto lastFocusedProfile = lastFocusedProfileOpt.value();

            auto tabViewItem = tab->GetTabViewItem();
            tabViewItem.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [this, lastFocusedProfile, tabViewItem]() {
                // _GetIconFromProfile has to run on the main thread
                const auto* const matchingProfile = _settings->FindProfile(lastFocusedProfile);
                if (matchingProfile)
                {
                    tabViewItem.Icon(App::_GetIconFromProfile(*matchingProfile));
                }
            });
        }
    }

    // Method Description:
    // - Get the title of the currently focused terminal control, and set it's
    //   tab's text to that text. If this tab is the focused tab, then also
    //   bubble this title to any listeners of our TitleChanged event.
    // Arguments:
    // - tab: the Tab to update the title for.
    void App::_UpdateTitle(std::shared_ptr<Tab> tab)
    {
        auto newTabTitle = tab->GetFocusedTitle();
        const auto lastFocusedProfileOpt = tab->GetFocusedProfile();
        const auto lastFocusedProfile = lastFocusedProfileOpt.value();
        const auto* const matchingProfile = _settings->FindProfile(lastFocusedProfile);

        auto tabTitle = matchingProfile->GetTabTitle();

        // TODO #608: If the settings don't want the terminal's text in the
        // tab, then display something else.

        if (tabTitle.empty())
        {
            tab->SetTabText(newTabTitle);
            if (_settings->GlobalSettings().GetShowTitleInTitlebar() &&
                tab->IsFocused())
            {
                _titleChangeHandlers(newTabTitle);
            }
        }
        else
        {
            tab->SetTabText(winrt::to_hstring(tabTitle.data()));
            if (_settings->GlobalSettings().GetShowTitleInTitlebar() &&
                tab->IsFocused())
            {
                _titleChangeHandlers(tabTitle);
            }

Review comment (suggestion):
Given that you don't appear to be checking the null-ness of this intermediate or anything, why not just write this all on one line instead of two?

(Also, is it OK to not check it for nullness? What's the value when the optional isn't filled?)

```suggestion
        const auto lastFocusedProfile = tab->GetFocusedProfile().value();
```

Code after:
        }

        _root.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [this]() {
            // Refresh the UI theme
            _ApplyTheme(_settings->GlobalSettings().GetRequestedTheme());

            // repopulate the new tab button's flyout with entries for each
            // profile, which might have changed
            _CreateNewTabFlyout();
        });
    }

    // Method Description:
    // - Get the icon of the currently focused terminal control, and set its
    //   tab's icon to that icon.
    // Arguments:
    // - tab: the Tab to update the title for.
    void App::_UpdateTabIcon(std::shared_ptr<Tab> tab)
    {
        const auto lastFocusedProfileOpt = tab->GetFocusedProfile();
        if (lastFocusedProfileOpt.has_value())
        {
            const auto lastFocusedProfile = lastFocusedProfileOpt.value();

            auto tabViewItem = tab->GetTabViewItem();
            tabViewItem.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [this, lastFocusedProfile, tabViewItem]() {
                // _GetIconFromProfile has to run on the main thread
                const auto* const matchingProfile = _settings->FindProfile(lastFocusedProfile);
                if (matchingProfile)
                {
                    tabViewItem.Icon(App::_GetIconFromProfile(*matchingProfile));
                }
            });
        }
    }

    // Method Description:
    // - Get the title of the currently focused terminal control, and set it's
    //   tab's text to that text. If this tab is the focused tab, then also
    //   bubble this title to any listeners of our TitleChanged event.
    // Arguments:
    // - tab: the Tab to update the title for.
    void App::_UpdateTitle(std::shared_ptr<Tab> tab)
    {
        auto newTabTitle = tab->GetFocusedTitle();
        const auto lastFocusedProfile = tab->GetFocusedProfile().value();
        const auto* const matchingProfile = _settings->FindProfile(lastFocusedProfile);

        const auto tabTitle = matchingProfile->GetTabTitle();

        // Checks if tab title has been set in the profile settings and