Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static ICollection<ISymbol> GetMissingEnumMembers(ISwitchOperation switch
if (!TryGetAllEnumMembers(switchExpressionType, enumMembers) ||
!TryRemoveExistingEnumMembers(switchStatement, enumMembers))
{
return SpecializedCollections.EmptyCollection<ISymbol>();
return [];
Copy link
Contributor

@sharwell sharwell Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ What type gets constructed for this case? I would expect this change introduced a new allocation due to the return type.

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/AnalyzerDriver/DeclarationComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static DeclarationInfo GetDeclarationInfo(SemanticModel model, SyntaxNo

internal static DeclarationInfo GetDeclarationInfo(SemanticModel model, SyntaxNode node, bool getSymbol, SyntaxNode executableCodeBlock, CancellationToken cancellationToken)
{
return GetDeclarationInfo(model, node, getSymbol, SpecializedCollections.SingletonEnumerable(executableCodeBlock), cancellationToken);
return GetDeclarationInfo(model, node, getSymbol, [executableCodeBlock], cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally do not welcome changes like this under Compilers.

}

internal static DeclarationInfo GetDeclarationInfo(SemanticModel model, SyntaxNode node, bool getSymbol, CancellationToken cancellationToken, params SyntaxNode[] executableCodeBlocks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ protected override IList<TextChange> FormatBasedOnEndToken(ParsedDocument docume
var endToken = root.FindToken(position);
var span = GetFormattedTextSpan(root, endToken);
if (span == null)
{
return SpecializedCollections.EmptyList<TextChange>();
}
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation


var formatter = document.LanguageServices.GetRequiredService<ISyntaxFormattingService>();
return formatter.GetFormattingResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
return classifications.Where(c => c.Span.IntersectsWith(span)).ToList();
}

return SpecializedCollections.EmptyList<ClassificationSpan>();
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public IReadOnlyList<Span> GetNameMatchRuns(string searchValue)
=> _searchResult.NameMatchSpans.NullToEmpty().SelectAsArray(ts => ts.ToSpan());

public IReadOnlyList<Span> GetAdditionalInformationMatchRuns(string searchValue)
=> SpecializedCollections.EmptyReadOnlyList<Span>();
=> [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
}
}

return SpecializedCollections.EmptyList<ClassificationSpan>();
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static IList<ITextView> GetTextViews(ITextBuffer textBuffer)
{
if (!s_map.TryGetValue(textBuffer, out var set))
{
return SpecializedCollections.EmptyList<ITextView>();
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}

return set.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ private void LogRenameSession(RenameLogMessage.UserActionOutcome outcome, bool p
outcome,
conflictResolutionFinishedComputing,
previewChanges,
SpecializedCollections.EmptyList<InlineRenameReplacementKind>()));
replacementKinds: []));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ internal static IList<T> SelectMatchingExtensionValues<T, TMetadata>(
where TMetadata : ILanguageMetadata
{
if (items == null)
{
return SpecializedCollections.EmptyList<T>();
}
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation


return items.Where(lazy => LanguageMatches(lazy.Metadata.Language, contentType, workspaceServices)).
Select(lazy => lazy.Value).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ End Event
End Class";
static ImmutableArray<IEventSymbol> GetExplicitInterfaceEvent(SemanticModel semanticModel)
{
var parameterSymbols = SpecializedCollections.EmptyList<AttributeData>();
return ImmutableArray.Create<IEventSymbol>(
new CodeGenerationEventSymbol(
GetTypeSymbol(typeof(System.ComponentModel.INotifyPropertyChanged))(semanticModel),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void SanityCheck()
var bufferMock = new Mock<ITextBuffer>(MockBehavior.Strict);
bufferMock.Setup(b => b.ContentType).Returns(contentType.Object);

var bufferCollection = new Collection<ITextBuffer>(SpecializedCollections.SingletonEnumerable(bufferMock.Object).ToList());
var bufferCollection = new Collection<ITextBuffer>([bufferMock.Object]);
var dummyReason = ConnectionReason.BufferGraphChange;

var exportProvider = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected override void ParseText(
}
else
{
nameParts = SpecializedCollections.EmptyList<NameAndArity>();
nameParts = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ internal static TextSpan CreateSpanForExplicitConstructorInitializer(Constructor
=> CreateSpan(constructorInitializer.ThisOrBaseKeyword, constructorInitializer.ArgumentList.CloseParenToken);

internal static IEnumerable<SyntaxToken> GetActiveTokensForExplicitConstructorInitializer(ConstructorInitializerSyntax constructorInitializer)
=> SpecializedCollections.SingletonEnumerable(constructorInitializer.ThisOrBaseKeyword).Concat(constructorInitializer.ArgumentList.DescendantTokens());
=> [constructorInitializer.ThisOrBaseKeyword, .. constructorInitializer.ArgumentList.DescendantTokens()];

internal static TextSpan CreateSpanForImplicitPrimaryConstructorInitializer(TypeDeclarationSyntax typeDeclaration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ protected override async Task<SyntaxNode> RewriteFieldNameAndAccessibilityAsync(

if (makePrivate)
{
var modifiers = SpecializedCollections.SingletonEnumerable(Token(SyntaxKind.PrivateKeyword))
.Concat(fieldSyntax.Modifiers.Where(m => !modifierKinds.Contains(m.Kind())));

root = root.ReplaceNode(fieldSyntax, fieldSyntax
.WithModifiers([.. modifiers])
.WithModifiers([Token(SyntaxKind.PrivateKeyword), .. fieldSyntax.Modifiers.Where(m => !modifierKinds.Contains(m.Kind()))])
.WithAdditionalAnnotations(Formatter.Annotation)
.WithLeadingTrivia(fieldSyntax.GetLeadingTrivia())
.WithTrailingTrivia(fieldSyntax.GetTrailingTrivia()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ protected static SignatureHelpSymbolParameter Convert(
#pragma warning disable CA1822 // Mark members as static - see obsolete message above.
protected IList<TaggedText> GetAwaitableUsage(IMethodSymbol method, SemanticModel semanticModel, int position)
#pragma warning restore CA1822 // Mark members as static
=> SpecializedCollections.EmptyList<TaggedText>();
=> [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void SyntaxNodeAction(
Descriptor, isExpression.GetLocation(),
styleOption.Notification,
context.Options,
SpecializedCollections.EmptyCollection<Location>(),
additionalLocations: [],
ImmutableDictionary<string, string?>.Empty));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ void Method()
new CodeChangeProviderMetadata("SuppressionProvider", languages: [LanguageNames.CSharp]));
var fixService = new CodeFixService(
diagnosticService,
SpecializedCollections.EmptyEnumerable<Lazy<IErrorLoggerService>>(),
SpecializedCollections.EmptyEnumerable<Lazy<CodeFixProvider, CodeChangeProviderMetadata>>(),
loggers: [],
fixers: [],
[suppressionProviderFactory]);
var document = GetDocumentAndSelectSpan(workspace, out var span);
var diagnostics = await diagnosticService.GetDiagnosticsForSpanAsync(document, span, CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private async Task<IEnumerable<ISymbol>> FindMembersAsync(
case 0:
// If there were no name parts, then we don't have any members to return.
// We only expect to hit this condition when the name provided does not parse.
return SpecializedCollections.EmptyList<ISymbol>();
return [];

case 1:
// They're just searching for a method name. Have to look through every type to find
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ private async Task<ImmutableArray<CodeActionOperation>> GetGenerateIntoExistingD
{
string includeUsingsOrImports = null;
if (!areFoldersValidIdentifiers)
{
folders = SpecializedCollections.EmptyList<string>();
}
folders = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation


// Now actually create the symbol that we want to add to the root namespace. The
// symbol may either be a named type (if we're not generating into a namespace) or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ internal sealed class SupportedPlatformData(Solution solution, List<ProjectId> i
public IList<SymbolDisplayPart> ToDisplayParts()
{
if (InvalidProjects == null || InvalidProjects.Count == 0)
{
return SpecializedCollections.EmptyList<SymbolDisplayPart>();
}
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation


var builder = new List<SymbolDisplayPart>();
builder.AddLineBreak();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<IEnumerable<DiagnosticData>> ComputeDiagnosticsAsync(Diagnosti
if (analyzer == FileContentLoadAnalyzer.Instance)
{
return loadDiagnostic != null
? SpecializedCollections.SingletonEnumerable(DiagnosticData.Create(loadDiagnostic, textDocument))
? [DiagnosticData.Create(loadDiagnostic, textDocument)]
: [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static EditSession CreateEditSession(
mockDebuggerService,
mockCompilationOutputsProvider,
NullPdbMatchingSourceTextProvider.Instance,
SpecializedCollections.EmptyEnumerable<KeyValuePair<DocumentId, CommittedSolution.DocumentState>>(),
initialDocumentStates: [],
reportDiagnostics: true);

if (initialState != CommittedSolution.DocumentState.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ internal class FSharpSignatureHelpItem

public Func<CancellationToken, IEnumerable<TaggedText>> DocumentationFactory { get; }

private static readonly Func<CancellationToken, IEnumerable<TaggedText>> s_emptyDocumentationFactory =
_ => SpecializedCollections.EmptyEnumerable<TaggedText>();
private static readonly Func<CancellationToken, IEnumerable<TaggedText>> s_emptyDocumentationFactory = _ => [];

public FSharpSignatureHelpItem(
bool isVariadic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ internal class FSharpSignatureHelpParameter
/// </summary>
public IList<TaggedText> SelectedDisplayParts { get; }

private static readonly Func<CancellationToken, IEnumerable<TaggedText>> s_emptyDocumentationFactory =
_ => SpecializedCollections.EmptyEnumerable<TaggedText>();
private static readonly Func<CancellationToken, IEnumerable<TaggedText>> s_emptyDocumentationFactory = _ => [];

public FSharpSignatureHelpParameter(
string name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,15 @@ public override bool MatchesScope(SyntaxNode node, EnvDTE.vsCMElement scope)
}

public override IEnumerable<SyntaxNode> GetOptionNodes(SyntaxNode parent)
{
// Only VB has Option statements
return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
}
=> [];

public override IEnumerable<SyntaxNode> GetImportNodes(SyntaxNode parent)
=> parent switch
{
CompilationUnitSyntax compilationUnit => compilationUnit.Usings,
BaseNamespaceDeclarationSyntax baseNamespace => baseNamespace.Usings,
_ => SpecializedCollections.EmptyEnumerable<SyntaxNode>(),
_ => [],
};

private static IEnumerable<SyntaxNode> GetAttributeNodes(SyntaxList<AttributeListSyntax> attributeDeclarationList)
Expand Down Expand Up @@ -343,34 +341,32 @@ public override IEnumerable<SyntaxNode> GetAttributeNodes(SyntaxNode parent)
return GetAttributeNodes(accessor.AttributeLists);
}

return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
return [];
}

public override IEnumerable<SyntaxNode> GetAttributeArgumentNodes(SyntaxNode parent)
{
if (parent is AttributeSyntax attribute)
{
if (attribute.ArgumentList == null)
{
return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
}
return [];

return attribute.ArgumentList.Arguments;
}

return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
return [];
}

public override IEnumerable<SyntaxNode> GetInheritsNodes(SyntaxNode parent)
{
// Only VB has Inherits statements
return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
return [];
}

public override IEnumerable<SyntaxNode> GetImplementsNodes(SyntaxNode parent)
{
// Only VB has Implements statements
return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
return [];
}

private static bool IsContainerNode(SyntaxNode container)
Expand Down Expand Up @@ -1465,7 +1461,7 @@ public override IEnumerable<SyntaxNode> GetParameterNodes(SyntaxNode parentNode)
return delegateDecl.ParameterList.Parameters;
}

return SpecializedCollections.EmptyEnumerable<ParameterSyntax>();
return [];
}

public override bool IsExpressionBodiedProperty(SyntaxNode node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ internal GenerateTypeDialogViewModel(
}
else
{
this.ProjectFolders = SpecializedCollections.EmptyList<string>();
this.ProjectFolders = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public NavigationBarClient(

_workspace = workspace;
_imageService = (IVsImageService2)serviceProvider.GetService(typeof(SVsImageService));
_projectItems = SpecializedCollections.EmptyList<NavigationBarProjectItem>();
_currentTypeItems = SpecializedCollections.EmptyList<NavigationBarItem>();
_projectItems = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

_currentTypeItems = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}

private NavigationBarItem? GetCurrentTypeItem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ private IList<TextSpanAndCookie> EnumOriginalCodeBlocksWorker(CancellationToken
var snapshot = this.SubjectBuffer.CurrentSnapshot;
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return SpecializedCollections.EmptyList<TextSpanAndCookie>();
}
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation


return document.GetVisibleCodeBlocks(cancellationToken)
.Select(tuple => new TextSpanAndCookie
Expand Down
4 changes: 2 additions & 2 deletions src/VisualStudio/Core/Def/Watson/FaultReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private static IList<string> CollectLogHubFilePaths()
// ignore failures
}

return SpecializedCollections.EmptyList<string>();
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}

private static IList<string> CollectServiceHubLogFilePaths()
Expand All @@ -291,7 +291,7 @@ private static IList<string> CollectServiceHubLogFilePaths()
// ignore failures
}

return SpecializedCollections.EmptyList<string>();
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This appears to be a new allocation

}

private static List<string> CollectFilePaths(string logDirectoryPath, string logFileExtension, Func<string, bool> shouldExcludeLogFile)
Expand Down
Loading