提交 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
Debug.Assert(ordinalMap.ContainsKey(oldTree)); // Checked by RemoveSyntaxTreeFromDeclarationMapAndTable
var oldOrdinal = ordinalMap[oldTree];
var newArray = this.SyntaxTrees.ToArray();
newArray[oldOrdinal] = (SyntaxTree)newTree;
var newArray = this.SyntaxTrees.SetItem(oldOrdinal, newTree);
// CONSIDER: should this be an operation on ImmutableDictionary?
ordinalMap = ordinalMap.Remove(oldTree);
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
}
// 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)
{
switch (severity)
......@@ -2051,7 +2050,7 @@ internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity
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).
if (report == ReportDiagnostic.Default)
{
......
......@@ -980,13 +980,12 @@ public override ImmutableArray<Symbol> GetMembers()
if (allMembers.Length > 1)
{
// The array isn't sorted. Sort it and remember that we sorted it.
Symbol[] membersArray = allMembers.ToArray();
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance);
ImmutableInterlocked.InterlockedExchange(ref this.lazyMembersFlattened, membersArray.AsImmutableOrNull());
allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance);
ImmutableInterlocked.InterlockedExchange(ref this.lazyMembersFlattened, allMembers);
}
ThreadSafeFlagOperations.Set(ref flags2, (FlattenedMembersIsSortedMask << FlattenedMembersIsSortedOffset));
return lazyMembersFlattened;
return allMembers;
}
}
......
......@@ -153,13 +153,12 @@ public override ImmutableArray<Symbol> GetMembers()
if (allMembers.Length >= 2)
{
// The array isn't sorted. Sort it and remember that we sorted it.
Symbol[] membersArray = allMembers.ToArray();
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance);
ImmutableInterlocked.InterlockedExchange(ref this.lazyAllMembers, membersArray.AsImmutableOrNull());
allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance);
ImmutableInterlocked.InterlockedExchange(ref this.lazyAllMembers, allMembers);
}
ThreadSafeFlagOperations.Set(ref flags, LazyAllMembersIsSorted);
return lazyAllMembers;
return allMembers;
}
}
......
......@@ -2205,7 +2205,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
If Not fieldType.IsDefinition Then
' 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(
fieldType, New ConsList(Of FieldSymbol)(field, current.Path)))
......@@ -3186,14 +3186,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim allMembers = Me.GetMembersUnordered()
If allMembers.Length >= 2 Then
Dim membersArray As Symbol() = allMembers.ToArray()
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance)
ImmutableInterlocked.InterlockedExchange(m_lazyMembersFlattened, membersArray.AsImmutableOrNull())
allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance)
ImmutableInterlocked.InterlockedExchange(m_lazyMembersFlattened, allMembers)
End If
ThreadSafeFlagOperations.Set(m_lazyState, StateFlags.FlattenedMembersIsSortedMask)
Return m_lazyMembersFlattened
Return allMembers
End If
End Function
......
......@@ -307,14 +307,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim allMembers = Me.GetMembersUnordered()
If allMembers.Length >= 2 Then
Dim membersArray As Symbol() = allMembers.ToArray()
Array.Sort(membersArray, LexicalOrderSymbolComparer.Instance)
ImmutableInterlocked.InterlockedExchange(m_lazyAllMembers, membersArray.AsImmutableOrNull())
allMembers = allMembers.Sort(LexicalOrderSymbolComparer.Instance)
ImmutableInterlocked.InterlockedExchange(m_lazyAllMembers, allMembers)
End If
ThreadSafeFlagOperations.Set(m_lazyState, StateFlags.AllMembersIsSorted)
Return m_lazyAllMembers
Return allMembers
End If
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册