-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop committing the whole buffer when determining if it's empty #15582
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7fb2e9
Avoid committing the entire buffer when figuring out if it's empty
DHowett 60b6338
ooga booga
DHowett adabfd5
Leonard for the save
DHowett 07e33d0
Deduplicate redundant offset subtraction
lhecker a8201c6
Avoid committing empty buffers on reflow
lhecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,19 @@ ROW& TextBuffer::_getRowByOffsetDirect(size_t offset) | |
return *reinterpret_cast<ROW*>(row); | ||
} | ||
|
||
// Returns the "user-visible" index of the last committed row, which can be used | ||
// to short-circuit some algorithms that try to scan the entire buffer. | ||
// Returns 0 if no rows are committed in. | ||
til::CoordType TextBuffer::_estimateOffsetOfLastCommittedRow() const noexcept | ||
{ | ||
const auto lastRowOffset = (_commitWatermark - _buffer.get()) / _bufferRowStride; | ||
// This subtracts 2 from the offset to account for the: | ||
// * scratchpad row at offset 0, whereas regular rows start at offset 1. | ||
// * fact that _commitWatermark points _past_ the last committed row, | ||
// but we want to return an index pointing at the last row. | ||
return std::max(0, gsl::narrow_cast<til::CoordType>(lastRowOffset - 2)); | ||
} | ||
|
||
// Retrieves a row from the buffer by its offset from the first row of the text buffer | ||
// (what corresponds to the top row of the screen buffer). | ||
const ROW& TextBuffer::GetRowByOffset(const til::CoordType index) const | ||
|
@@ -807,7 +820,7 @@ til::point TextBuffer::GetLastNonSpaceCharacter(std::optional<const Microsoft::C | |
|
||
til::point coordEndOfText; | ||
// Search the given viewport by starting at the bottom. | ||
coordEndOfText.y = viewport.BottomInclusive(); | ||
coordEndOfText.y = std::min(viewport.BottomInclusive(), _estimateOffsetOfLastCommittedRow()); | ||
|
||
const auto& currRow = GetRowByOffset(coordEndOfText.y); | ||
// The X position of the end of the valid text is the Right draw boundary (which is one beyond the final valid character) | ||
|
@@ -2622,7 +2635,7 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, | |
// printable char gets reset. See GH #12567 | ||
auto newRowY = newCursor.GetPosition().y + 1; | ||
const auto newHeight = newBuffer.GetSize().Height(); | ||
const auto oldHeight = oldBuffer.GetSize().Height(); | ||
const auto oldHeight = oldBuffer._estimateOffsetOfLastCommittedRow() + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this, because it's a simple change, but speeds up reflow of empty buffers quite a lot. It needs +1 because |
||
for (; | ||
iOldRow < oldHeight && newRowY < newHeight; | ||
iOldRow++) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that the
calculation is effectively the same as
and so it kind of merges with the other -1 we already had to form -2.
I also felt like it's neat because now it's only 2 lines of code and the
std::max
ensures it's impossible to return negative indices.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmmm I agree with you, but I probably should have been the one to commit the suggestion ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I thought this would take some load off your shoulders.