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.
Two major improvements in the
store/line_manipulation.go
andstore/pager.go
functions for line-wrap and moving the pager one item down.Line-Wrap
Major change is to switch to using a
strings.Builder
instead of using string concatenation. With thestrings.Builder
.This allows to reduce the number of required allocation and when growing the internal buffer by the estimated size we also reduce the runtime calls to
growslice
.Benchmarks:
concatenation
BenchmarkBuildLines-12 3884172 287.7 ns/op 376 B/op 8 allocs/op
strings.Builder
BenchmarkLineWrapShort-12 51005851 215.4 ns/op 240 B/op 3 allocs/op
MovePosition
basically fixing the issue what happens when the buffer is not completlly full yet and the lines to be inserted wrap in more lines than are available in the buffer. This caused the buffer to either swallow lines or leave N lines empty (not filled) in the buffer. Since we are now not leaving lines out the benchmarks increased a little but nothing unexpected.
from
BenchmarkMovePosition-12 51899091 206.8 ns/op 111 B/op 4 allocs/op
to
BenchmarkMovePosition-12 49591225 220.7 ns/op 515 B/op 4 allocs/op
Lastly, test cases have been added, updated, extended or removed. Same as for old functions where where updated/re-written such as:
breakInLines
buildLines
lineWrap
while maintaining the same parameters only the name changedMoveDown
has been deprecated effectively with PR and will be removed.