Skip to content

Commit f592268

Browse files
committed
Add ref scope annotations to ImmutableArrayBuilder<T>
1 parent f87610a commit f592268

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/CommunityToolkit.Mvvm.SourceGenerators/Helpers/ImmutableArrayBuilder{T}.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.Buffers;
1010
using System.Collections.Immutable;
11+
using System.Diagnostics.CodeAnalysis;
1112
using System.Runtime.CompilerServices;
1213

1314
namespace CommunityToolkit.Mvvm.SourceGenerators.Helpers;
@@ -16,7 +17,7 @@ namespace CommunityToolkit.Mvvm.SourceGenerators.Helpers;
1617
/// A helper type to build sequences of values with pooled buffers.
1718
/// </summary>
1819
/// <typeparam name="T">The type of items to create sequences for.</typeparam>
19-
internal struct ImmutableArrayBuilder<T> : IDisposable
20+
internal ref struct ImmutableArrayBuilder<T>
2021
{
2122
/// <summary>
2223
/// The rented <see cref="Writer"/> instance to use.
@@ -51,6 +52,7 @@ public int Count
5152
/// <summary>
5253
/// Gets the data written to the underlying buffer so far, as a <see cref="ReadOnlySpan{T}"/>.
5354
/// </summary>
55+
[UnscopedRef]
5456
public readonly ReadOnlySpan<T> WrittenSpan
5557
{
5658
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -67,7 +69,7 @@ public readonly void Add(T item)
6769
/// Adds the specified items to the end of the array.
6870
/// </summary>
6971
/// <param name="items">The items to add at the end of the array.</param>
70-
public readonly void AddRange(ReadOnlySpan<T> items)
72+
public readonly void AddRange(scoped ReadOnlySpan<T> items)
7173
{
7274
this.writer!.AddRange(items);
7375
}
@@ -92,7 +94,7 @@ public override readonly string ToString()
9294
return this.writer!.WrittenSpan.ToString();
9395
}
9496

95-
/// <inheritdoc/>
97+
/// <inheritdoc cref="IDisposable.Dispose"/>
9698
public void Dispose()
9799
{
98100
Writer? writer = this.writer;

0 commit comments

Comments
 (0)