Skip to content

Commit

Permalink
Initialize rows lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Jun 7, 2023
1 parent f0705fb commit 11c2215
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 247 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect/expect.txt
Expand Up @@ -439,6 +439,7 @@ DECMSR
DECNKM
DECNRCM
DECOM
decommit
DECPCTERM
DECPS
DECRARA
Expand Down
17 changes: 12 additions & 5 deletions src/buffer/out/Row.cpp
Expand Up @@ -82,10 +82,7 @@ ROW::ROW(wchar_t* charsBuffer, uint16_t* charOffsetsBuffer, uint16_t rowWidth, c
_attr{ rowWidth, fillAttribute },
_columnCount{ rowWidth }
{
if (_chars.data())
{
_init();
}
_init();
}

void ROW::SetWrapForced(const bool wrap) noexcept
Expand Down Expand Up @@ -147,6 +144,15 @@ void ROW::TransferAttributes(const til::small_rle<TextAttribute, uint16_t, 1>& a
_attr.resize_trailing_extent(gsl::narrow<uint16_t>(newWidth));
}

void ROW::CopyFrom(const ROW& source)
{
til::CoordType begin = 0;
CopyRangeFrom(0, til::CoordTypeMax, source, begin, til::CoordTypeMax);
TransferAttributes(source.Attributes(), _columnCount);
_lineRendition = source._lineRendition;
_wrapForced = source._wrapForced;
}

// Returns the previous possible cursor position, preceding the given column.
// Returns 0 if column is less than or equal to 0.
til::CoordType ROW::NavigateToPrevious(til::CoordType column) const noexcept
Expand Down Expand Up @@ -464,7 +470,8 @@ try
}

WriteHelper h{ *this, columnBegin, columnLimit, chars };
if (!h.IsValid())
// Copying from the ourselves would destroy the data we need to determine where it needs to go in the first place.
if (!h.IsValid() || this == &other)
{
return h.colBeg;
}
Expand Down
14 changes: 14 additions & 0 deletions src/buffer/out/Row.hpp
Expand Up @@ -60,6 +60,19 @@ struct RowWriteState
class ROW final
{
public:
static constexpr size_t CalculateRowSize() noexcept
{
return sizeof(ROW);
}
static constexpr size_t CalculateCharsBufferSize(size_t columns) noexcept
{
return columns * sizeof(wchar_t);
}
static constexpr size_t CalculateCharOffsetsBufferSize(size_t columns) noexcept
{
return (columns + 1) * sizeof(uint16_t);
}

ROW() = default;
ROW(wchar_t* charsBuffer, uint16_t* charOffsetsBuffer, uint16_t rowWidth, const TextAttribute& fillAttribute);

Expand All @@ -78,6 +91,7 @@ class ROW final

void Reset(const TextAttribute& attr);
void TransferAttributes(const til::small_rle<TextAttribute, uint16_t, 1>& attr, til::CoordType newWidth);
void CopyFrom(const ROW& source);

til::CoordType NavigateToPrevious(til::CoordType column) const noexcept;
til::CoordType NavigateToNext(til::CoordType column) const noexcept;
Expand Down

0 comments on commit 11c2215

Please sign in to comment.