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.
in the previous function in the
store/pager
the funcMoveDown
would fill the pager's buffer up initially and once full truncate lines from the beginning in order to append the new lines at the end of the buffer. Lastly,MoveDow
would recompute thebufferView
if certain conditions where meet.However, this function ignored that each time we do
buffer = buffer[n:]
we create a new slice still with the same backing array just a different window but with a changed capacity for the new slice. Than when appending the new lines withappend(buffer, lines...)
the capacity would not be enough and doubled in size. All this lead to a moving capacity..The new function
MovePosition
shifts all items in the buffer to the left by N where N is the number of new lines which will be added to the buffer. As a result the capacity does not move and stays the same.Even-though not noticeable in the benchmarks my assumption was that due to the static capacity runtime calls to
growSlice
andmemMove
would be reduced. Not completely sure why it's not reflecting in the benchmarks which where about the same (MovePosition
took about 20ns longer but had about 200 fewer B/op).Lastly, included in this Pull-Request is the change that
MovePosition
no longer builds thebufferView
if the refresh-rate allows it to and the pager is not in the statepaused
. This functionality has been moved to thepager.String
function.current benchmarks for the new
MovePosition
func are: