Repository navigation
Conversation
- Cover indentation, continuing a line, AppendItem, Empty and editing lines
- Keep the line being written in a StringBuilder rather than concatenating it on every Append - Split on new lines with ordinal IndexOf instead of string.Split and a closure - Compare new lines ordinally rather than with the current culture - Indent in place instead of allocating a Line scope and an indentation string
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
StructuredStringBuilderis on the hot path of every LoquiPrint, and it allocated a lot more than the text it produced. EveryAppendconcatenated onto the last line again and split its input withstring.Splitplus a closure. EveryAppendLineallocated aLinescope and a fresh indentation string through aStringBuilder.StartsWith(Environment.NewLine)also compared using the current culture, which turned out to be the slowest part.This keeps the line being written in a
StringBuilderand only turns it into a string once the line ends. It splits on new lines with an ordinalIndexOf, and writes indentation straight into the line.DepthStrand the rest of the public API stay as they are.Printing ~1000 lines the way Loqui's generated
Printdoes:This should not change any output. The first commit adds tests that pin the current behavior; they pass both before and after the change. The only difference is that the debug-only
LineAppendedno longer sees the indentation strings, or the empty line the constructor used to append.