Repository: microsoft/terminal
File: src/cascadia/TerminalCore/Terminal.hpp (C++)

Code before:
#pragma endregion

#ifndef NDEBUG
    bool _suppressLockChecks = false;
#endif

private:
    std::function<void(std::wstring_view)> _pfnWriteInput;
    std::function<void()> _pfnWarningBell;
    std::function<void(std::wstring_view)> _pfnTitleChanged;
    std::function<void(wil::zwstring_view)> _pfnCopyToClipboard;

    // I've specifically put this instance here as it requires
    //   alignas(std::hardware_destructive_interference_size)
    // for best performance.
    //
    // But we can abuse the fact that the surrounding members rarely change and are huge
    // (std::function is like 64 bytes) to create some natural padding without wasting space.
    til::recursive_ticket_lock _readWriteLock;

    std::function<void(const int, const int, const int)> _pfnScrollPositionChanged;
    std::function<void()> _pfnTaskbarProgressChanged;
    std::function<void(bool)> _pfnShowWindowChanged;
    std::function<void(const int, const int, const std::chrono::microseconds)> _pfnPlayMidiNote;
    std::function<void(std::wstring_view, unsigned int)> _pfnCompletionsChanged;
    std::function<void(std::wstring_view, const til::CoordType&)> _pfnSearchMissingCommand;
    std::function<void()> _pfnClearQuickFix;

    RenderSettings _renderSettings;
    std::unique_ptr<::Microsoft::Console::VirtualTerminal::StateMachine> _stateMachine;
    ::Microsoft::Console::VirtualTerminal::TerminalInput _terminalInput;

    std::optional<std::wstring> _title;
    std::wstring _startingTitle;
    std::optional<til::color> _startingTabColor;

    std::vector<til::point_span> _searchHighlights;
    size_t _searchHighlightFocused = 0;

    mutable std::vector<til::point_span> _lastSelectionSpans;
    mutable til::generation_t _lastSelectionGeneration{};

    CursorType _defaultCursorShape = CursorType::Legacy;

    til::enumset<Mode> _systemMode{ Mode::AutoWrap };

    bool _snapOnInput = true;
    bool _altGrAliasing = true;
    bool _suppressApplicationTitle = false;
    bool _trimBlockSelection = false;
    bool _autoMarkPrompts = false;

Review comment (bug):
Only large classes (like a large array) or those expensive to copy (like `wstring` - creates a complete, separate copy of the entire string no matter how large) should be passed by reference. Since `CoordType` is a primitive integer, we should pass it by value. This results in it being passed in a CPU register and also makes debugging simpler.

Only a few types are in the gray area in between (namely reference counted types: `com_ptr`, WinRT instances, `hstring`, etc. They're slightly expensive to copy but not terribly so.)

Code after:
#pragma endregion

#ifndef NDEBUG
    bool _suppressLockChecks = false;
#endif

private:
    std::function<void(std::wstring_view)> _pfnWriteInput;
    std::function<void()> _pfnWarningBell;
    std::function<void(std::wstring_view)> _pfnTitleChanged;
    std::function<void(wil::zwstring_view)> _pfnCopyToClipboard;

    // I've specifically put this instance here as it requires
    //   alignas(std::hardware_destructive_interference_size)
    // for best performance.
    //
    // But we can abuse the fact that the surrounding members rarely change and are huge
    // (std::function is like 64 bytes) to create some natural padding without wasting space.
    til::recursive_ticket_lock _readWriteLock;

    std::function<void(const int, const int, const int)> _pfnScrollPositionChanged;
    std::function<void()> _pfnTaskbarProgressChanged;
    std::function<void(bool)> _pfnShowWindowChanged;
    std::function<void(const int, const int, const std::chrono::microseconds)> _pfnPlayMidiNote;
    std::function<void(std::wstring_view, unsigned int)> _pfnCompletionsChanged;
    std::function<void(std::wstring_view, const til::CoordType)> _pfnSearchMissingCommand;
    std::function<void()> _pfnClearQuickFix;

    RenderSettings _renderSettings;
    std::unique_ptr<::Microsoft::Console::VirtualTerminal::StateMachine> _stateMachine;
    ::Microsoft::Console::VirtualTerminal::TerminalInput _terminalInput;

    std::optional<std::wstring> _title;
    std::wstring _startingTitle;
    std::optional<til::color> _startingTabColor;

    std::vector<til::point_span> _searchHighlights;
    size_t _searchHighlightFocused = 0;

    mutable std::vector<til::point_span> _lastSelectionSpans;
    mutable til::generation_t _lastSelectionGeneration{};

    CursorType _defaultCursorShape = CursorType::Legacy;

    til::enumset<Mode> _systemMode{ Mode::AutoWrap };

    bool _snapOnInput = true;
    bool _altGrAliasing = true;
    bool _suppressApplicationTitle = false;
    bool _trimBlockSelection = false;
    bool _autoMarkPrompts = false;