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

SA1028 memory optimizations #1160

Merged
merged 2 commits into from
Aug 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace System.Linq
{
using Collections.Generic;
using Microsoft.CodeAnalysis;

/// <summary>
/// This class supports a subset of LINQ operations on <see cref="SyntaxTriviaList"/> without requiring boxing of
/// operands as an <see cref="IEnumerable{T}"/>.
/// </summary>
internal static class SyntaxTriviaListEnumerable
{
/// <summary>
/// Determines if a <see cref="SyntaxTriviaList"/> contains a specific <see cref="SyntaxTrivia"/>.
/// </summary>
/// <remarks>
/// <para>This method allows callers to avoid boxing the <see cref="SyntaxTriviaList"/> as an
/// <see cref="IEnumerable{T}"/>.</para>
/// </remarks>
/// <param name="list">The source list.</param>
/// <param name="trivia">The element to look for in the list.</param>
/// <returns>
/// <see langword="true"/> if <paramref name="list"/> contains <paramref name="trivia"/>; otherwise,
/// <see langword="false"/>.
/// </returns>
internal static bool Contains(this SyntaxTriviaList list, SyntaxTrivia trivia)
{
foreach (SyntaxTrivia item in list)
{
if (item.Equals(trivia))
{
return true;
}
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void Initialize(AnalysisContext context)
private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context)
{
var root = context.Tree.GetRoot(context.CancellationToken);
var text = root.GetText();
var text = context.Tree.GetText(context.CancellationToken);

foreach (var trivia in root.DescendantTrivia(descendIntoTrivia: true))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<Compile Include="LayoutRules\SA1518CodeMustNotContainBlankLinesAtEndOfFile.cs" />
<Compile Include="LayoutRules\SA1519CurlyBracketsMustNotBeOmittedFromMultiLineChildStatement.cs" />
<Compile Include="LayoutRules\SA1520UseCurlyBracketsConsistently.cs" />
<Compile Include="LinqHelpers\SyntaxTriviaListEnumerable.cs" />
<Compile Include="MaintainabilityRules\MaintainabilityResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down