Skip to content

Commit

Permalink
Avoid ImmutableArray collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jan 16, 2024
1 parent 2cd327b commit 9589fd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public ImmutableArray<IMethodSymbol> GetDeconstructionAssignmentMethods(Semantic
return builder.ToImmutableAndClear();
}

return [];
return ImmutableArray<IMethodSymbol>.Empty;
}

public ImmutableArray<IMethodSymbol> GetDeconstructionForEachMethods(SemanticModel semanticModel, SyntaxNode node)
Expand All @@ -217,7 +217,7 @@ public ImmutableArray<IMethodSymbol> GetDeconstructionForEachMethods(SemanticMod
return builder.ToImmutableAndClear();
}

return [];
return ImmutableArray<IMethodSymbol>.Empty;
}

private static void FlattenDeconstructionMethods(DeconstructionInfo deconstruction, ref TemporaryArray<IMethodSymbol> builder)
Expand Down Expand Up @@ -282,7 +282,7 @@ public IEnumerable<ISymbol> GetDeclaredSymbols(
public ImmutableArray<ISymbol> GetBestOrAllSymbols(SemanticModel semanticModel, SyntaxNode? node, SyntaxToken token, CancellationToken cancellationToken)
{
if (node == null)
return [];
return ImmutableArray<ISymbol>.Empty;

return node switch
{
Expand All @@ -295,7 +295,7 @@ ForEachVariableStatementSyntax _ when token.Kind() == SyntaxKind.InKeyword => Ge
static ImmutableArray<ISymbol> GetCallingConventionSymbols(SemanticModel model, FunctionPointerUnmanagedCallingConventionSyntax syntax)
{
var type = model.Compilation.TryGetCallingConventionSymbol(syntax.Name.ValueText);
return type is null ? [] : [type];
return type is null ? ImmutableArray<ISymbol>.Empty : ImmutableArray.Create<ISymbol>(type);
}
}

Expand Down Expand Up @@ -355,7 +355,7 @@ private static ImmutableArray<ISymbol> GetSymbolInfo(SemanticModel semanticModel

//Only in the orderby clause a comma can bind to a symbol.
if (token.IsKind(SyntaxKind.CommaToken))
return [];
return ImmutableArray<ISymbol>.Empty;

// If we're on 'var' then asking for the symbol-info will get us the symbol *without* nullability
// information. Check for that, and try to return the type with nullability info if it has it.
Expand All @@ -367,7 +367,7 @@ private static ImmutableArray<ISymbol> GetSymbolInfo(SemanticModel semanticModel
type.Equals(symbol, SymbolEqualityComparer.Default) &&
!type.Equals(symbol, SymbolEqualityComparer.IncludeNullability))
{
return [type];
return ImmutableArray.Create<ISymbol>(type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public static ImmutableArray<ISymbol> GetAllSymbols(this SymbolInfo info)
=> GetAllSymbolsWorker(info).Distinct();

private static ImmutableArray<ISymbol> GetAllSymbolsWorker(this SymbolInfo info)
=> info.Symbol == null ? info.CandidateSymbols : [info.Symbol, .. info.CandidateSymbols];
=> info.Symbol == null ? info.CandidateSymbols : info.CandidateSymbols.Insert(0, info.Symbol);

public static ISymbol? GetAnySymbol(this SymbolInfo info)
=> info.Symbol ?? info.CandidateSymbols.FirstOrDefault();

public static ImmutableArray<ISymbol> GetBestOrAllSymbols(this SymbolInfo info)
{
if (info.Symbol != null)
return [info.Symbol];
return ImmutableArray.Create(info.Symbol);

if (info.CandidateSymbols.Contains(null!))
{
Expand Down

0 comments on commit 9589fd2

Please sign in to comment.