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

Some optimizations in StringLineGroup #399

Merged
merged 1 commit into from
Feb 18, 2020

Conversation

KrisVandermotten
Copy link
Contributor

This PR contributes a few improvements to StringLineGroup.

RemoveAt(int)

A memory leak was fixed and code duplication reduced.

ToSlice(List<LineOffset>)

First, the case where Count == 1 has been moved before the case where Count == 0, simply because it is so much more common. Indeed, out of 1023 unit tests that call this method, 872 execute the Count == 1 branch, but none of them execute the Count == 0 branch.

Secondly, the loop was restructured to simplify it and reduce code duplication. Using ref var line = ref Lines[i];, the Lines array is indexed only once per iteration.

Iterator.NextChar()

_offset++; has been moved into the if branch, so that the _offset--; in the else branch can be removed.

@xoofx xoofx merged commit ef5b958 into xoofx:master Feb 18, 2020
@xoofx
Copy link
Owner

xoofx commented Feb 18, 2020

Thanks!

@KrisVandermotten KrisVandermotten deleted the StringLineGroup branch February 18, 2020 20:55
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.

2 participants