提交 21b35dcf 编写于 作者: P Pharring

PERF: Array.Clone

A couple of allocations showed up in the typing traces due to Array.Clone via ImmutableArray<T>ToArray(). These can be reduced by using methods on ImmutableArray<T> directly. (changeset 1215219)
上级 766e4386
...@@ -815,14 +815,13 @@ public new CSharpCompilation ReplaceSyntaxTree(SyntaxTree oldTree, SyntaxTree ne ...@@ -815,14 +815,13 @@ public new CSharpCompilation ReplaceSyntaxTree(SyntaxTree oldTree, SyntaxTree ne
Debug.Assert(ordinalMap.ContainsKey(oldTree)); // Checked by RemoveSyntaxTreeFromDeclarationMapAndTable Debug.Assert(ordinalMap.ContainsKey(oldTree)); // Checked by RemoveSyntaxTreeFromDeclarationMapAndTable
var oldOrdinal = ordinalMap[oldTree]; var oldOrdinal = ordinalMap[oldTree];
var newArray = this.SyntaxTrees.ToArray(); var newArray = this.SyntaxTrees.SetItem(oldOrdinal, newTree);
newArray[oldOrdinal] = (SyntaxTree)newTree;
// CONSIDER: should this be an operation on ImmutableDictionary? // CONSIDER: should this be an operation on ImmutableDictionary?
ordinalMap = ordinalMap.Remove(oldTree); ordinalMap = ordinalMap.Remove(oldTree);
ordinalMap = ordinalMap.SetItem(newTree, oldOrdinal); ordinalMap = ordinalMap.SetItem(newTree, oldOrdinal);
return UpdateSyntaxTrees(newArray.AsImmutableOrNull(), ordinalMap, declMap, declTable, referenceDirectivesChanged); return UpdateSyntaxTrees(newArray, ordinalMap, declMap, declTable, referenceDirectivesChanged);
} }
} }
...@@ -2014,7 +2013,7 @@ private static bool FilterAndAppendDiagnostics(DiagnosticBag accumulator, IEnume ...@@ -2014,7 +2013,7 @@ private static bool FilterAndAppendDiagnostics(DiagnosticBag accumulator, IEnume
} }
// Take a warning and return the final deposition of the given warning, // Take a warning and return the final deposition of the given warning,
// based on both commmand line options and pragmas // based on both command line options and pragmas
internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity, string id, int warningLevel, Location location, CompilationOptions options, string kind) internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity, string id, int warningLevel, Location location, CompilationOptions options, string kind)
{ {
switch (severity) switch (severity)
...@@ -2051,7 +2050,7 @@ internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity ...@@ -2051,7 +2050,7 @@ internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity
return ReportDiagnostic.Suppress; return ReportDiagnostic.Suppress;
} }
// Unless sepcific warning options are defined (/warnaserror[+|-]:<n> or /nowarn:<n>, // Unless specific warning options are defined (/warnaserror[+|-]:<n> or /nowarn:<n>,
// follow the global option (/warnaserror[+|-] or /nowarn). // follow the global option (/warnaserror[+|-] or /nowarn).
if (report == ReportDiagnostic.Default) if (report == ReportDiagnostic.Default)
{ {
......
...@@ -980,13 +980,12 @@ public override ImmutableArray<Symbol> GetMembers() ...@@ -980,13 +980,12 @@ public override ImmutableArray<Symbol> GetMembers()
if (allMembers.Length > 1) if (allMembers.Length > 1)
{ {
// The array isn't sorted. Sort it and remember that we sorted it. // The array isn't sorted. Sort it and remember that we sorted it.
Symbol[] membersArray = allMembers.ToArray(); allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance);
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance); ImmutableInterlocked.InterlockedExchange(ref this.lazyMembersFlattened, allMembers);
ImmutableInterlocked.InterlockedExchange(ref this.lazyMembersFlattened, membersArray.AsImmutableOrNull());
} }
ThreadSafeFlagOperations.Set(ref flags2, (FlattenedMembersIsSortedMask << FlattenedMembersIsSortedOffset)); ThreadSafeFlagOperations.Set(ref flags2, (FlattenedMembersIsSortedMask << FlattenedMembersIsSortedOffset));
return lazyMembersFlattened; return allMembers;
} }
} }
......
...@@ -153,13 +153,12 @@ public override ImmutableArray<Symbol> GetMembers() ...@@ -153,13 +153,12 @@ public override ImmutableArray<Symbol> GetMembers()
if (allMembers.Length >= 2) if (allMembers.Length >= 2)
{ {
// The array isn't sorted. Sort it and remember that we sorted it. // The array isn't sorted. Sort it and remember that we sorted it.
Symbol[] membersArray = allMembers.ToArray(); allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance);
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance); ImmutableInterlocked.InterlockedExchange(ref this.lazyAllMembers, allMembers);
ImmutableInterlocked.InterlockedExchange(ref this.lazyAllMembers, membersArray.AsImmutableOrNull());
} }
ThreadSafeFlagOperations.Set(ref flags, LazyAllMembersIsSorted); ThreadSafeFlagOperations.Set(ref flags, LazyAllMembersIsSorted);
return lazyAllMembers; return allMembers;
} }
} }
......
...@@ -2205,7 +2205,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ...@@ -2205,7 +2205,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
If Not fieldType.IsDefinition Then If Not fieldType.IsDefinition Then
' Types constructred from generic types are considered to be a separate types. We never report ' Types constructred from generic types are considered to be a separate types. We never report
' errros on such types. We also process only fields actually changed compared to original generic type. ' errors on such types. We also process only fields actually changed compared to original generic type.
data.Queue.Enqueue(New StructureCircularityDetectionDataSet.QueueElement( data.Queue.Enqueue(New StructureCircularityDetectionDataSet.QueueElement(
fieldType, New ConsList(Of FieldSymbol)(field, current.Path))) fieldType, New ConsList(Of FieldSymbol)(field, current.Path)))
...@@ -3186,14 +3186,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ...@@ -3186,14 +3186,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim allMembers = Me.GetMembersUnordered() Dim allMembers = Me.GetMembersUnordered()
If allMembers.Length >= 2 Then If allMembers.Length >= 2 Then
Dim membersArray As Symbol() = allMembers.ToArray() allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance)
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance) ImmutableInterlocked.InterlockedExchange(m_lazyMembersFlattened, allMembers)
ImmutableInterlocked.InterlockedExchange(m_lazyMembersFlattened, membersArray.AsImmutableOrNull())
End If End If
ThreadSafeFlagOperations.Set(m_lazyState, StateFlags.FlattenedMembersIsSortedMask) ThreadSafeFlagOperations.Set(m_lazyState, StateFlags.FlattenedMembersIsSortedMask)
Return m_lazyMembersFlattened Return allMembers
End If End If
End Function End Function
......
...@@ -307,14 +307,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ...@@ -307,14 +307,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim allMembers = Me.GetMembersUnordered() Dim allMembers = Me.GetMembersUnordered()
If allMembers.Length >= 2 Then If allMembers.Length >= 2 Then
Dim membersArray As Symbol() = allMembers.ToArray() allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance)
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance) ImmutableInterlocked.InterlockedExchange(m_lazyAllMembers, allMembers)
ImmutableInterlocked.InterlockedExchange(m_lazyAllMembers, membersArray.AsImmutableOrNull())
End If End If
ThreadSafeFlagOperations.Set(m_lazyState, StateFlags.AllMembersIsSorted) ThreadSafeFlagOperations.Set(m_lazyState, StateFlags.AllMembersIsSorted)
Return m_lazyAllMembers Return allMembers
End If End If
End Function End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册