Skip to content
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

Line wrap #23

Merged
merged 9 commits into from
Aug 17, 2023
Merged

Line wrap #23

merged 9 commits into from
Aug 17, 2023

Conversation

KonstantinGasser
Copy link
Owner

@KonstantinGasser KonstantinGasser commented Aug 17, 2023

Two major improvements in the store/line_manipulation.go and store/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 the strings.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
  • => both replaced by lineWrap while maintaining the same parameters only the name changed
  • MoveDown has been deprecated effectively with PR and will be removed.

@KonstantinGasser KonstantinGasser merged commit de2cc73 into main Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant