Skip to content

Commit

Permalink
! Used ImmutableArray.Builder instead of List
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Feb 1, 2021
1 parent 54d6ded commit 47acf3f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Codist/QuickInfo/CSharpQuickInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ static void ShowInterfaceImplementation<TSymbol>(QiContainer qiContent, TSymbol
if (interfaces.Length == 0) {
return;
}
var explicitIntfs = new List<ITypeSymbol>(3);
var explicitIntfs = ImmutableArray.CreateBuilder<ITypeSymbol>(3);
ThemedTipDocument info = null;
var returnType = symbol.GetReturnType();
var parameters = symbol.GetParameters();
Expand Down Expand Up @@ -911,7 +911,8 @@ static void ShowInterfaceMembers(QiContainer qiContent, INamedTypeSymbol type) {
}

static void ShowMembers(INamedTypeSymbol type, ThemedTipDocument doc, bool isInherit) {
var members = new List<ISymbol>(type.GetMembers().RemoveAll(m => (m as IMethodSymbol)?.AssociatedSymbol != null || m.IsImplicitlyDeclared));
var members = ImmutableArray.CreateBuilder<ISymbol>();
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();
Expand Down Expand Up @@ -1046,8 +1047,8 @@ static void ShowInterfaces(QiContainer qiContent, ITypeSymbol type) {
if (interfaces.Length == 0 && showAll == false) {
return;
}
var declaredInterfaces = new List<INamedTypeSymbol>(interfaces.Length);
var inheritedInterfaces = new List<INamedTypeSymbol>(5);
var declaredInterfaces = ImmutableArray.CreateBuilder<INamedTypeSymbol>(interfaces.Length);
var inheritedInterfaces = ImmutableArray.CreateBuilder<INamedTypeSymbol>(5);
INamedTypeSymbol disposable = null;
foreach (var item in interfaces) {
if (item.Name == Disposable) {
Expand Down Expand Up @@ -1253,7 +1254,7 @@ void ShowArgumentInfo(QiContainer qiContent, SyntaxNode argument) {

static void ShowAnonymousTypeInfo(QiContainer container, ISymbol symbol) {
ITypeSymbol t;
List<ITypeSymbol> types = null;
ImmutableArray<ITypeSymbol>.Builder types = null;
switch (symbol.Kind) {
case SymbolKind.NamedType:
if ((t = symbol as ITypeSymbol).IsAnonymousType) {
Expand Down Expand Up @@ -1285,7 +1286,7 @@ static void ShowAnonymousTypeInfo(QiContainer container, ISymbol symbol) {
ShowAnonymousTypes(container, types, symbol);
}

void ShowAnonymousTypes(QiContainer c, List<ITypeSymbol> anonymousTypes, ISymbol currentSymbol) {
void ShowAnonymousTypes(QiContainer c, ImmutableArray<ITypeSymbol>.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++) {
Expand Down Expand Up @@ -1320,8 +1321,8 @@ void ShowAnonymousTypes(QiContainer c, List<ITypeSymbol> anonymousTypes, ISymbol
c.Overrider?.OverrideAnonymousTypeInfo(d);
c.Insert(0, d);
}
void Add(ref List<ITypeSymbol> list, ITypeSymbol type) {
if ((list ?? (list = new List<ITypeSymbol>())).Contains(type) == false) {
void Add(ref ImmutableArray<ITypeSymbol>.Builder list, ITypeSymbol type) {
if ((list ?? (list = ImmutableArray.CreateBuilder<ITypeSymbol>())).Contains(type) == false) {
list.Add(type);
}
if (type.ContainingType?.IsAnonymousType == true) {
Expand All @@ -1340,7 +1341,7 @@ public void Dispose() {

sealed class QiContainer
{
readonly List<object> _List = new List<object>();
ImmutableArray<object>.Builder _List = ImmutableArray.CreateBuilder<object>();
public readonly IQuickInfoOverrider Overrider;

public QiContainer(IQuickInfoOverrider overrider) {
Expand Down

0 comments on commit 47acf3f

Please sign in to comment.