-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Produce less string allocs while formatting documents #73452
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,21 +346,15 @@ public static int GetStartPositionOfSpan(SyntaxToken token) | |
|
||
public static bool HasAnyWhitespaceElasticTrivia(SyntaxToken previousToken, SyntaxToken currentToken) | ||
{ | ||
if ((!previousToken.ContainsAnnotations && !currentToken.ContainsAnnotations) || | ||
(!previousToken.HasTrailingTrivia && !currentToken.HasLeadingTrivia)) | ||
{ | ||
if (!previousToken.ContainsAnnotations && !currentToken.ContainsAnnotations) | ||
return false; | ||
|
||
if (!previousToken.HasTrailingTrivia && !currentToken.HasLeadingTrivia) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just formatting so i could understand the code. |
||
return false; | ||
} | ||
|
||
return previousToken.TrailingTrivia.HasAnyWhitespaceElasticTrivia() || currentToken.LeadingTrivia.HasAnyWhitespaceElasticTrivia(); | ||
} | ||
|
||
public static bool IsNull<T>(T t) where T : class | ||
=> t == null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mostly pointless. so inlined. |
||
|
||
public static bool IsNotNull<T>(T t) where T : class | ||
=> !IsNull(t); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not called. |
||
|
||
public static TextSpan GetFormattingSpan(SyntaxNode root, TextSpan span) | ||
{ | ||
Contract.ThrowIfNull(root); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting TriviaData is not cheap. It allocates up front (The substring between tokesn). I looked into changing that, but it was non-trivial. so thsi was the expedient solution.