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

Code before:
        // Raise a FoundMatch event, which the control will use to notify
        // narrator if there was any results in the buffer
        _FoundMatchHandlers(*this, *foundResults);
    }

    Windows::Foundation::Collections::IVector<int32_t> ControlCore::SearchResultRows()
    {
        auto lock = _terminal->LockForWriting();
        if (_searcher.ResetIfStale(*GetRenderData()))
        {
            auto results = std::vector<int32_t>();

            auto lastRow = til::CoordTypeMin;
            for (const auto& match : _searcher.Results())
            {
                const auto row{ match.start.y };
                if (row != lastRow)
                {
                    results.push_back(row);
                    lastRow = row;
                }
            }
            _cachedSearchResultRows = winrt::single_threaded_vector<int32_t>(std::move(results));
        }

        return _cachedSearchResultRows ? _cachedSearchResultRows : winrt::single_threaded_vector<int32_t>();
    }

    void ControlCore::ClearSearch()
    {
        _terminal->AlwaysNotifyOnBufferRotation(false);
        _searcher = {};
    }

    void ControlCore::Close()
    {
        if (!_IsClosing())
        {
            _closing = true;

            // Ensure Close() doesn't hang, waiting for MidiAudio to finish playing an hour long song.
            _midiAudio.BeginSkip();

            // Stop accepting new output and state changes before we disconnect everything.
            _connectionOutputEventRevoker.revoke();
            _connectionStateChangedRevoker.revoke();
            _connection.Close();
        }
    }

    void ControlCore::_rendererWarning(const HRESULT hr)

Review comment (performance):
i still don't understand. is `null` not an acceptable return value for this function?

is there ever a case where we get here and we didn't (1) have or (2) newly populate the cached rows???

Code after:
        // Raise a FoundMatch event, which the control will use to notify
        // narrator if there was any results in the buffer
        _FoundMatchHandlers(*this, *foundResults);
    }

    Windows::Foundation::Collections::IVector<int32_t> ControlCore::SearchResultRows()
    {
        auto lock = _terminal->LockForWriting();
        if (_searcher.ResetIfStale(*GetRenderData()))
        {
            auto results = std::vector<int32_t>();

            auto lastRow = til::CoordTypeMin;
            for (const auto& match : _searcher.Results())
            {
                const auto row{ match.start.y };
                if (row != lastRow)
                {
                    results.push_back(row);
                    lastRow = row;
                }
            }
            _cachedSearchResultRows = winrt::single_threaded_vector<int32_t>(std::move(results));
        }

        return _cachedSearchResultRows;
    }

    void ControlCore::ClearSearch()
    {
        _terminal->AlwaysNotifyOnBufferRotation(false);
        _searcher = {};
    }

    void ControlCore::Close()
    {
        if (!_IsClosing())
        {
            _closing = true;

            // Ensure Close() doesn't hang, waiting for MidiAudio to finish playing an hour long song.
            _midiAudio.BeginSkip();

            // Stop accepting new output and state changes before we disconnect everything.
            _connectionOutputEventRevoker.revoke();
            _connectionStateChangedRevoker.revoke();
            _connection.Close();
        }
    }

    void ControlCore::_rendererWarning(const HRESULT hr)