Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
// The minimum delay between updating the TSF input control.
constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);

// The minimum delay between updating the locations of regex patterns
constexpr const auto UpdatePatternLocationsInterval = std::chrono::milliseconds(500);

// The minimum delay between emitting warning bells
constexpr const auto TerminalWarningBellInterval = std::chrono::milliseconds(1000);

DEFINE_ENUM_FLAG_OPERATORS(winrt::Microsoft::Terminal::Control::CopyFormat);

namespace winrt::Microsoft::Terminal::Control::implementation
{
    TermControl::TermControl(IControlSettings settings,
                             TerminalConnection::ITerminalConnection connection) :
        _initializedTerminal{ false },
        _settings{ settings },
        _closing{ false },
        _isInternalScrollBarUpdate{ false },
        _autoScrollVelocity{ 0 },
        _autoScrollingPointerPoint{ std::nullopt },
        _autoScrollTimer{},
        _lastAutoScrollUpdateTime{ std::nullopt },
        _cursorTimer{},
        _blinkTimer{},
        _bellLightTimer{},
        _searchBox{ nullptr },
        _bellLightAnimation{ Window::Current().Compositor().CreateScalarKeyFrameAnimation() }
    {
        InitializeComponent();

        _interactivity = winrt::make_self<ControlInteractivity>(settings, connection);
        _core = _interactivity->GetCore();

        // Use a manual revoker on the output event, so we can immediately stop
        // worrying about it on destruction.
        _coreOutputEventToken = _core->ReceivedOutput({ this, &TermControl::_coreReceivedOutput });

        // These events might all be triggered by the connection, but that
        // should be drained and closed before we complete destruction. So these
        // are safe.
        _core->ScrollPositionChanged({ this, &TermControl::_ScrollPositionChanged });
        _core->WarningBell({ this, &TermControl::_coreWarningBell });
        _core->CursorPositionChanged({ this, &TermControl::_CursorPositionChanged });

        // This event is specifically triggered by the renderer thread, a BG thread. Use a weak ref here.
        _core->RendererEnteredErrorState({ get_weak(), &TermControl::_RendererEnteredErrorState });

        // These callbacks can only really be triggered by UI interactions. So
        // they don't need weak refs - they can't be triggered unless we're
        // alive.

Review comment (suggestion):
Optionals have a default constructor and you don't need to initialize them here.
Usually you only need to do that, if you want an "uncommon" (non-default) initialization, or you got primitive types as members, which aren't initialized by default.

The same is true for about half of the other initializations here.
It might be easier to reason about this, if we mostly migrate from initialization lists like this one to default member initializations, where you declare the initial value of members directly in class declaration in the header file.

Code after:
// The minimum delay between updating the TSF input control.
constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);

// The minimum delay between updating the locations of regex patterns
constexpr const auto UpdatePatternLocationsInterval = std::chrono::milliseconds(500);

// The minimum delay between emitting warning bells
constexpr const auto TerminalWarningBellInterval = std::chrono::milliseconds(1000);

DEFINE_ENUM_FLAG_OPERATORS(winrt::Microsoft::Terminal::Control::CopyFormat);

namespace winrt::Microsoft::Terminal::Control::implementation
{
    TermControl::TermControl(IControlSettings settings,
                             TerminalConnection::ITerminalConnection connection) :
        _initializedTerminal{ false },
        _settings{ settings },
        _closing{ false },
        _isInternalScrollBarUpdate{ false },
        _autoScrollVelocity{ 0 },
        _autoScrollingPointerPoint{ std::nullopt },
        _autoScrollTimer{},
        _lastAutoScrollUpdateTime{ std::nullopt },
        _cursorTimer{},
        _blinkTimer{},
        _searchBox{ nullptr },
        _bellLightAnimation{ Window::Current().Compositor().CreateScalarKeyFrameAnimation() }
    {
        InitializeComponent();

        _interactivity = winrt::make_self<ControlInteractivity>(settings, connection);
        _core = _interactivity->GetCore();

        // Use a manual revoker on the output event, so we can immediately stop
        // worrying about it on destruction.
        _coreOutputEventToken = _core->ReceivedOutput({ this, &TermControl::_coreReceivedOutput });

        // These events might all be triggered by the connection, but that
        // should be drained and closed before we complete destruction. So these
        // are safe.
        _core->ScrollPositionChanged({ this, &TermControl::_ScrollPositionChanged });
        _core->WarningBell({ this, &TermControl::_coreWarningBell });
        _core->CursorPositionChanged({ this, &TermControl::_CursorPositionChanged });

        // This event is specifically triggered by the renderer thread, a BG thread. Use a weak ref here.
        _core->RendererEnteredErrorState({ get_weak(), &TermControl::_RendererEnteredErrorState });

        // These callbacks can only really be triggered by UI interactions. So
        // they don't need weak refs - they can't be triggered unless we're
        // alive.
        _core->BackgroundColorChanged({ this, &TermControl::_BackgroundColorChangedHandler });