Skip to content

Commit

Permalink
Implement ICollection<T> on ArrayBuilder (#73659)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored May 23, 2024
1 parent c2d84f5 commit 5fec4fb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private static bool CanBeOptional(ParameterSymbol parameter, bool isMethodGroupC

private static int? CheckForDuplicateNamedArgument(AnalyzedArguments arguments)
{
if (arguments.Names.IsEmpty())
if (arguments.Names.IsEmpty)
{
// No checks if there are no named arguments
return null;
Expand Down
8 changes: 4 additions & 4 deletions src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ private static MethodSymbol GetEntryPoint(CSharpCompilation compilation, PEModul
Debug.Assert(lazyVariableSlotAllocator is null);
Debug.Assert(stateMachineTypeOpt is null);
Debug.Assert(codeCoverageSpans.IsEmpty);
Debug.Assert(lambdaDebugInfoBuilder.IsEmpty());
Debug.Assert(lambdaRuntimeRudeEditsBuilder.IsEmpty());
Debug.Assert(closureDebugInfoBuilder.IsEmpty());
Debug.Assert(stateMachineStateDebugInfoBuilder.IsEmpty());
Debug.Assert(lambdaDebugInfoBuilder.IsEmpty);
Debug.Assert(lambdaRuntimeRudeEditsBuilder.IsEmpty);
Debug.Assert(closureDebugInfoBuilder.IsEmpty);
Debug.Assert(stateMachineStateDebugInfoBuilder.IsEmpty);

lambdaDebugInfoBuilder.Free();
lambdaRuntimeRudeEditsBuilder.Free();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void Close(bool isMethodBody)

if (isMethodBody)
{
Debug.Assert(_lazyPreviousContextVariables?.IsEmpty() != false);
Debug.Assert(_lazyPreviousContextVariables?.IsEmpty != false);
_lazyPreviousContextVariables?.Free();
_lazyPreviousContextVariables = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected StateMachineRewriter(
Debug.Assert(compilationState != null);
Debug.Assert(diagnostics != null);
Debug.Assert(diagnostics.DiagnosticBag != null);
Debug.Assert(stateMachineStateDebugInfoBuilder.IsEmpty());
Debug.Assert(stateMachineStateDebugInfoBuilder.IsEmpty);

this.body = body;
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private ImmutableArray<SwitchBucket> GenerateSwitchBuckets(int startLabelIndex,
// merge top bucket on stack into newBucket, and pop bucket from stack
// End While

while (!switchBucketsStack.IsEmpty())
while (!switchBucketsStack.IsEmpty)
{
// get the bucket at top of the stack
SwitchBucket prevBucket = switchBucketsStack.Peek();
Expand All @@ -217,7 +217,7 @@ private ImmutableArray<SwitchBucket> GenerateSwitchBuckets(int startLabelIndex,
curStartLabelIndex++;
}

Debug.Assert(!switchBucketsStack.IsEmpty());
Debug.Assert(!switchBucketsStack.IsEmpty);

// crumble leaf buckets into degenerate buckets where possible
var crumbled = ArrayBuilder<SwitchBucket>.GetInstance();
Expand Down
8 changes: 7 additions & 1 deletion src/Dependencies/PooledObjects/ArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.PooledObjects
{
[DebuggerDisplay("Count = {Count,nq}")]
[DebuggerTypeProxy(typeof(ArrayBuilder<>.DebuggerProxy))]
internal sealed partial class ArrayBuilder<T> : IReadOnlyCollection<T>, IReadOnlyList<T>
internal sealed partial class ArrayBuilder<T> : IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>
{
/// <summary>
/// See <see cref="Free()"/> for an explanation of this constant value.
Expand Down Expand Up @@ -139,6 +139,12 @@ public T this[int index]
}
}

public bool IsReadOnly
=> false;

public bool IsEmpty
=> Count == 0;

/// <summary>
/// Write <paramref name="value"/> to slot <paramref name="index"/>.
/// Fills in unallocated slots preceding the <paramref name="index"/>, if any.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public async Task<DocumentAnalysisResults> AnalyzeDocumentAsync(
AnalyzeUnchangedActiveMemberBodies(diagnostics, syntacticEdits.Match, newText, oldActiveStatements, newActiveStatementSpans, newActiveStatements, newExceptionRegions, cancellationToken);
Debug.Assert(newActiveStatements.All(a => a != null));

if (!diagnostics.IsEmpty())
if (!diagnostics.IsEmpty)
{
LogRudeEdits(diagnostics, newText, filePath);
}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ private void AnalyzeChangedMemberBody(
// We create syntax map even if it's not necessary: if any data member initializers are active/contain lambdas.
// Since initializers are usually simple the map should not be large enough to make it worth optimizing it away.
var matchingNodes =
(!activeNodes.IsEmpty() ||
(!activeNodes.IsEmpty ||
newStateMachineInfo.HasSuspensionPoints ||
newBodyHasLambdas ||
IsConstructorWithMemberInitializers(newMember, cancellationToken) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void AddStatement(LinePositionSpan unmappedLineSpan, ActiveStatement activeState

if (!hasAnyLineDirectives)
{
Debug.Assert(builder.IsEmpty());
Debug.Assert(builder.IsEmpty);

if (DocumentPathMap.TryGetValue(oldTree.FilePath, out var activeStatements))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Core/Portable/EditAndContinue/EditSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ public async ValueTask<SolutionUpdate> EmitSolutionUpdateAsync(Solution solution
}

await PopulateChangedAndAddedDocumentsAsync(oldProject, newProject, changedOrAddedDocuments, cancellationToken).ConfigureAwait(false);
if (changedOrAddedDocuments.IsEmpty())
if (changedOrAddedDocuments.IsEmpty)
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ await ComputeRefactoringsAsync(
intentDataProvider.FallbackOptions,
cancellationToken).ConfigureAwait(false);

if (actions.IsEmpty())
if (actions.IsEmpty)
{
return [];
}
Expand Down

0 comments on commit 5fec4fb

Please sign in to comment.