From 47acf3f046157ef342ae6f0243c001c4fbacbf1c Mon Sep 17 00:00:00 2001 From: WMJ Date: Mon, 1 Feb 2021 10:17:26 +0800 Subject: [PATCH] ! Used ImmutableArray.Builder instead of List --- Codist/QuickInfo/CSharpQuickInfo.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Codist/QuickInfo/CSharpQuickInfo.cs b/Codist/QuickInfo/CSharpQuickInfo.cs index 72ae9bbf..f9ba7da3 100644 --- a/Codist/QuickInfo/CSharpQuickInfo.cs +++ b/Codist/QuickInfo/CSharpQuickInfo.cs @@ -862,7 +862,7 @@ static void ShowInterfaceImplementation(QiContainer qiContent, TSymbol if (interfaces.Length == 0) { return; } - var explicitIntfs = new List(3); + var explicitIntfs = ImmutableArray.CreateBuilder(3); ThemedTipDocument info = null; var returnType = symbol.GetReturnType(); var parameters = symbol.GetParameters(); @@ -911,7 +911,8 @@ static void ShowInterfaceMembers(QiContainer qiContent, INamedTypeSymbol type) { } static void ShowMembers(INamedTypeSymbol type, ThemedTipDocument doc, bool isInherit) { - var members = new List(type.GetMembers().RemoveAll(m => (m as IMethodSymbol)?.AssociatedSymbol != null || m.IsImplicitlyDeclared)); + var members = ImmutableArray.CreateBuilder(); + members.AddRange(type.GetMembers().RemoveAll(m => (m as IMethodSymbol)?.AssociatedSymbol != null || m.IsImplicitlyDeclared)); members.Sort(CodeAnalysisHelper.CompareByAccessibilityKindName); foreach (var member in members) { var t = new ThemedTipText(); @@ -1046,8 +1047,8 @@ static void ShowInterfaces(QiContainer qiContent, ITypeSymbol type) { if (interfaces.Length == 0 && showAll == false) { return; } - var declaredInterfaces = new List(interfaces.Length); - var inheritedInterfaces = new List(5); + var declaredInterfaces = ImmutableArray.CreateBuilder(interfaces.Length); + var inheritedInterfaces = ImmutableArray.CreateBuilder(5); INamedTypeSymbol disposable = null; foreach (var item in interfaces) { if (item.Name == Disposable) { @@ -1253,7 +1254,7 @@ void ShowArgumentInfo(QiContainer qiContent, SyntaxNode argument) { static void ShowAnonymousTypeInfo(QiContainer container, ISymbol symbol) { ITypeSymbol t; - List types = null; + ImmutableArray.Builder types = null; switch (symbol.Kind) { case SymbolKind.NamedType: if ((t = symbol as ITypeSymbol).IsAnonymousType) { @@ -1285,7 +1286,7 @@ static void ShowAnonymousTypeInfo(QiContainer container, ISymbol symbol) { ShowAnonymousTypes(container, types, symbol); } - void ShowAnonymousTypes(QiContainer c, List anonymousTypes, ISymbol currentSymbol) { + void ShowAnonymousTypes(QiContainer c, ImmutableArray.Builder anonymousTypes, ISymbol currentSymbol) { const string AnonymousNumbers = "abcdefghijklmnopqrstuvwxyz"; var d = new ThemedTipDocument().AppendTitle(IconIds.AnonymousType, R.T_AnonymousType); for (var i = 0; i < anonymousTypes.Count; i++) { @@ -1320,8 +1321,8 @@ void ShowAnonymousTypes(QiContainer c, List anonymousTypes, ISymbol c.Overrider?.OverrideAnonymousTypeInfo(d); c.Insert(0, d); } - void Add(ref List list, ITypeSymbol type) { - if ((list ?? (list = new List())).Contains(type) == false) { + void Add(ref ImmutableArray.Builder list, ITypeSymbol type) { + if ((list ?? (list = ImmutableArray.CreateBuilder())).Contains(type) == false) { list.Add(type); } if (type.ContainingType?.IsAnonymousType == true) { @@ -1340,7 +1341,7 @@ public void Dispose() { sealed class QiContainer { - readonly List _List = new List(); + ImmutableArray.Builder _List = ImmutableArray.CreateBuilder(); public readonly IQuickInfoOverrider Overrider; public QiContainer(IQuickInfoOverrider overrider) {