@@ -20,9 +20,8 @@ public struct ZCharArray : IDisposable
2020 private static readonly ArrayPool < char >
2121 Pool = ArrayPool < char > . Create ( MaxBufferCapacity , 100 ) ;
2222
23- private char [ ] _bufferArray ;
23+ private char [ ] ? _bufferArray ;
2424 private int _currentLength ;
25- private bool _isDisposed ;
2625
2726 /// <summary>
2827 /// The default capacity of the array.
@@ -49,7 +48,6 @@ public ZCharArray(int length)
4948 {
5049 _bufferArray = Pool . Rent ( length ) ;
5150 _currentLength = 0 ;
52- _isDisposed = false ;
5351 }
5452
5553 /// <summary>
@@ -98,7 +96,7 @@ public int Capacity
9896 get
9997 {
10098 ThrowIfDisposed ( ) ;
101- return _bufferArray . Length ;
99+ return _bufferArray ! . Length ;
102100 }
103101 }
104102
@@ -121,7 +119,7 @@ public void Reset()
121119 private void Grow ( int length )
122120 {
123121 var newArray = Pool . Rent ( length ) ;
124- Array . Copy ( _bufferArray , newArray , Math . Min ( _bufferArray . Length , length ) ) ;
122+ Array . Copy ( _bufferArray ! , newArray , Math . Min ( _bufferArray ! . Length , length ) ) ;
125123 Pool . Return ( _bufferArray ) ;
126124 _bufferArray = newArray ;
127125 }
@@ -135,7 +133,7 @@ public void Write(Span<char> data)
135133 {
136134 ThrowIfDisposed ( ) ;
137135 GrowBufferIfNeeded ( data . Length ) ;
138- data . CopyTo ( _bufferArray . AsSpan ( _currentLength , data . Length ) ) ;
136+ data . CopyTo ( _bufferArray ! . AsSpan ( _currentLength , data . Length ) ) ;
139137 _currentLength += data . Length ;
140138 }
141139
@@ -148,7 +146,7 @@ public void Write(ReadOnlySpan<char> data)
148146 {
149147 ThrowIfDisposed ( ) ;
150148 GrowBufferIfNeeded ( data . Length ) ;
151- data . CopyTo ( _bufferArray . AsSpan ( _currentLength , data . Length ) ) ;
149+ data . CopyTo ( _bufferArray ! . AsSpan ( _currentLength , data . Length ) ) ;
152150 _currentLength += data . Length ;
153151 }
154152
@@ -161,7 +159,7 @@ public void Write(string data)
161159 {
162160 ThrowIfDisposed ( ) ;
163161 GrowBufferIfNeeded ( data . Length ) ;
164- data . AsSpan ( ) . CopyTo ( _bufferArray . AsSpan ( _currentLength , data . Length ) ) ;
162+ data . AsSpan ( ) . CopyTo ( _bufferArray ! . AsSpan ( _currentLength , data . Length ) ) ;
165163 _currentLength += data . Length ;
166164 }
167165
@@ -174,7 +172,7 @@ public void Write(char c)
174172 {
175173 ThrowIfDisposed ( ) ;
176174 GrowBufferIfNeeded ( 1 ) ;
177- _bufferArray [ _currentLength ++ ] = c ;
175+ _bufferArray ! [ _currentLength ++ ] = c ;
178176 }
179177
180178 /// <summary>
@@ -190,7 +188,7 @@ public void Write(char c, int count)
190188
191189 for ( var i = 0 ; i < count ; i ++ )
192190 {
193- _bufferArray [ _currentLength ++ ] = c ;
191+ _bufferArray ! [ _currentLength ++ ] = c ;
194192 }
195193 }
196194
@@ -248,7 +246,7 @@ private void GrowBufferIfNeeded(int dataLength)
248246 /// <summary>
249247 /// Returns <see langword="true"/> if the array has been disposed.
250248 /// </summary>
251- public bool IsDisposed => _isDisposed ;
249+ public bool IsDisposed => _bufferArray is null ;
252250
253251 private void ThrowIfDisposed ( )
254252 {
@@ -263,15 +261,15 @@ private void ThrowIfDisposed()
263261 public override string ToString ( )
264262 {
265263 ThrowIfDisposed ( ) ;
266- return new string ( _bufferArray , 0 , _currentLength ) ;
264+ return new string ( _bufferArray ! , 0 , _currentLength ) ;
267265 }
268266
269267 /// <summary>
270268 /// Disposes the array, returning it to the <see cref="ArrayPool{T}"/>.
271269 /// </summary>
272270 public void Dispose ( )
273271 {
274- if ( _isDisposed ) return ;
272+ if ( IsDisposed ) return ;
275273
276274 Pool . Return ( _bufferArray ! , clearArray : true ) ;
277275 _bufferArray = null ;
0 commit comments