8
8
using System ;
9
9
using System . Buffers ;
10
10
using System . Collections . Immutable ;
11
+ using System . Diagnostics . CodeAnalysis ;
11
12
using System . Runtime . CompilerServices ;
12
13
13
14
namespace CommunityToolkit . Mvvm . SourceGenerators . Helpers ;
@@ -16,7 +17,7 @@ namespace CommunityToolkit.Mvvm.SourceGenerators.Helpers;
16
17
/// A helper type to build sequences of values with pooled buffers.
17
18
/// </summary>
18
19
/// <typeparam name="T">The type of items to create sequences for.</typeparam>
19
- internal struct ImmutableArrayBuilder < T > : IDisposable
20
+ internal ref struct ImmutableArrayBuilder < T >
20
21
{
21
22
/// <summary>
22
23
/// The rented <see cref="Writer"/> instance to use.
@@ -51,6 +52,7 @@ public int Count
51
52
/// <summary>
52
53
/// Gets the data written to the underlying buffer so far, as a <see cref="ReadOnlySpan{T}"/>.
53
54
/// </summary>
55
+ [ UnscopedRef ]
54
56
public readonly ReadOnlySpan < T > WrittenSpan
55
57
{
56
58
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -67,7 +69,7 @@ public readonly void Add(T item)
67
69
/// Adds the specified items to the end of the array.
68
70
/// </summary>
69
71
/// <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 )
71
73
{
72
74
this . writer ! . AddRange ( items ) ;
73
75
}
@@ -92,7 +94,7 @@ public override readonly string ToString()
92
94
return this . writer ! . WrittenSpan . ToString ( ) ;
93
95
}
94
96
95
- /// <inheritdoc/>
97
+ /// <inheritdoc cref="IDisposable.Dispose" />
96
98
public void Dispose ( )
97
99
{
98
100
Writer ? writer = this . writer ;
0 commit comments