Skip to content

Commit

Permalink
Perf: save text buffer size for frequent access
Browse files Browse the repository at this point in the history
  • Loading branch information
skyline75489 committed Oct 28, 2019
1 parent 634687b commit aa791b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ TextBuffer::TextBuffer(const COORD screenBufferSize,
_cursor{ cursorSize, *this },
_storage{},
_unicodeStorage{},
_size{ Viewport::Empty() },
_renderTarget{ renderTarget }
{
// initialize ROWs
for (size_t i = 0; i < static_cast<size_t>(screenBufferSize.Y); ++i)
{
_storage.emplace_back(static_cast<SHORT>(i), screenBufferSize.X, _currentAttributes, this);
}

_UpdateSize();
}

// Routine Description:
Expand Down Expand Up @@ -622,7 +625,7 @@ COORD TextBuffer::GetLastNonSpaceCharacter(const Microsoft::Console::Types::View
// Return Value:
// - Coordinate position in screen coordinates of the character just before the cursor.
// - NOTE: Will return 0,0 if already in the top left corner
COORD TextBuffer::_GetPreviousFromCursor() const
COORD TextBuffer::_GetPreviousFromCursor() const noexcept
{
COORD coordPosition = GetCursor().GetPosition();

Expand Down Expand Up @@ -651,9 +654,10 @@ const SHORT TextBuffer::GetFirstRowIndex() const noexcept
{
return _firstRow;
}
const Viewport TextBuffer::GetSize() const

const Viewport TextBuffer::GetSize() const noexcept
{
return Viewport::FromDimensions({ 0, 0 }, { gsl::narrow<SHORT>(_storage.at(0).size()), gsl::narrow<SHORT>(_storage.size()) });
return _size;
}

void TextBuffer::_SetFirstRowIndex(const SHORT FirstRowIndex) noexcept
Expand Down Expand Up @@ -844,6 +848,9 @@ void TextBuffer::Reset()
// Also take advantage of the row ID refresh loop to resize the rows in the X dimension
// and cleanup the UnicodeStorage characters that might fall outside the resized buffer.
_RefreshRowIDs(newSize.X);

// Update the buffer size.
_UpdateSize();
}
CATCH_RETURN();

Expand Down Expand Up @@ -896,6 +903,11 @@ void TextBuffer::_RefreshRowIDs(std::optional<SHORT> newRowWidth)
_unicodeStorage.Remap(rowMap, newRowWidth);
}

void TextBuffer::_UpdateSize()
{
_size = Viewport::FromDimensions({ 0, 0 }, { gsl::narrow<SHORT>(_storage.at(0).size()), gsl::narrow<SHORT>(_storage.size()) });
}

void TextBuffer::_NotifyPaint(const Viewport& viewport) const
{
_renderTarget.TriggerRedraw(viewport);
Expand Down
8 changes: 6 additions & 2 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class TextBuffer final

const SHORT GetFirstRowIndex() const noexcept;

const Microsoft::Console::Types::Viewport GetSize() const;
const Microsoft::Console::Types::Viewport GetSize() const noexcept;

void ScrollRows(const SHORT firstRow, const SHORT size, const SHORT delta);

Expand Down Expand Up @@ -156,18 +156,22 @@ class TextBuffer final

SHORT _firstRow; // indexes top row (not necessarily 0)

Microsoft::Console::Types::Viewport _size;

TextAttribute _currentAttributes;

// storage location for glyphs that can't fit into the buffer normally
UnicodeStorage _unicodeStorage;

void _RefreshRowIDs(std::optional<SHORT> newRowWidth);

void _UpdateSize();

Microsoft::Console::Render::IRenderTarget& _renderTarget;

void _SetFirstRowIndex(const SHORT FirstRowIndex) noexcept;

COORD _GetPreviousFromCursor() const;
COORD _GetPreviousFromCursor() const noexcept;

void _SetWrapOnCurrentRow();
void _AdjustWrapOnCurrentRow(const bool fSet);
Expand Down
2 changes: 1 addition & 1 deletion src/types/ScreenInfoUiaProviderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::get_SupportedTextSelection(_Out_ Suppo

#pragma endregion

const COORD ScreenInfoUiaProviderBase::_getScreenBufferCoords() const
const COORD ScreenInfoUiaProviderBase::_getScreenBufferCoords() const noexcept
{
return _getTextBuffer().GetSize().Dimensions();
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/ScreenInfoUiaProviderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace Microsoft::Console::Types
// mechanism for multi-threaded code.
std::map<EVENTID, bool> _signalFiringMapping;

const COORD _getScreenBufferCoords() const;
const COORD _getScreenBufferCoords() const noexcept;
const TextBuffer& _getTextBuffer() const noexcept;
const Viewport _getViewport() const noexcept;
void _LockConsole() noexcept;
Expand Down

0 comments on commit aa791b0

Please sign in to comment.