@@ -71,9 +71,7 @@ public ArrayPoolBufferWriter(ArrayPool<T> pool)
7171 /// Initializes a new instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
7272 /// </summary>
7373 /// <param name="initialCapacity">The minimum capacity with which to initialize the underlying buffer.</param>
74- /// <exception cref="ArgumentException">
75- /// Thrown when <paramref name="initialCapacity"/> is not positive (i.e. less than or equal to 0).
76- /// </exception>
74+ /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="initialCapacity"/> is not valid.</exception>
7775 public ArrayPoolBufferWriter ( int initialCapacity )
7876 : this ( ArrayPool < T > . Shared , initialCapacity )
7977 {
@@ -84,19 +82,15 @@ public ArrayPoolBufferWriter(int initialCapacity)
8482 /// </summary>
8583 /// <param name="pool">The <see cref="ArrayPool{T}"/> instance to use.</param>
8684 /// <param name="initialCapacity">The minimum capacity with which to initialize the underlying buffer.</param>
87- /// <exception cref="ArgumentException">
88- /// Thrown when <paramref name="initialCapacity"/> is not positive (i.e. less than or equal to 0).
89- /// </exception>
85+ /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="initialCapacity"/> is not valid.</exception>
9086 public ArrayPoolBufferWriter ( ArrayPool < T > pool , int initialCapacity )
9187 {
92- if ( initialCapacity <= 0 )
93- {
94- ThrowArgumentOutOfRangeExceptionForInitialCapacity ( ) ;
95- }
96-
9788 // Since we're using pooled arrays, we can rent the buffer with the
9889 // default size immediately, we don't need to use lazy initialization
9990 // to save unnecessary memory allocations in this case.
91+ // Additionally, we don't need to manually throw the exception if
92+ // the requested size is not valid, as that'll be thrown automatically
93+ // by the array pool in use when we try to rent an array with that size.
10094 this . pool = pool ;
10195 this . array = pool . Rent ( initialCapacity ) ;
10296 this . index = 0 ;
@@ -314,14 +308,6 @@ public override string ToString()
314308 return $ "Microsoft.Toolkit.HighPerformance.Buffers.ArrayPoolBufferWriter<{ typeof ( T ) } >[{ this . index } ]";
315309 }
316310
317- /// <summary>
318- /// Throws an <see cref="ArgumentOutOfRangeException"/> when the initial capacity is invalid.
319- /// </summary>
320- private static void ThrowArgumentOutOfRangeExceptionForInitialCapacity ( )
321- {
322- throw new ArgumentOutOfRangeException ( "initialCapacity" , "The initial capacity must be a positive value" ) ;
323- }
324-
325311 /// <summary>
326312 /// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
327313 /// </summary>
0 commit comments