Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Rent()

override T[] System.Buffers.ConfigurableArrayPool< T >.Rent ( int minimumLength)
inline

Definition at line 137 of file ConfigurableArrayPool.cs.

138 {
139 if (minimumLength < 0)
140 {
141 throw new ArgumentOutOfRangeException("minimumLength");
142 }
143 if (minimumLength == 0)
144 {
145 return Array.Empty<T>();
146 }
147 ArrayPoolEventSource log = ArrayPoolEventSource.Log;
148 int num = Utilities.SelectBucketIndex(minimumLength);
149 T[] array;
150 if (num < _buckets.Length)
151 {
152 int num2 = num;
153 do
154 {
155 array = _buckets[num2].Rent();
156 if (array != null)
157 {
158 if (log.IsEnabled())
159 {
160 log.BufferRented(array.GetHashCode(), array.Length, Id, _buckets[num2].Id);
161 }
162 return array;
163 }
164 }
165 while (++num2 < _buckets.Length && num2 != num + 2);
166 array = new T[_buckets[num]._bufferLength];
167 }
168 else
169 {
170 array = new T[minimumLength];
171 }
172 if (log.IsEnabled())
173 {
174 int hashCode = array.GetHashCode();
175 log.BufferRented(hashCode, array.Length, Id, -1);
176 log.BufferAllocated(hashCode, array.Length, Id, -1, (num >= _buckets.Length) ? ArrayPoolEventSource.BufferAllocatedReason.OverMaximumSize : ArrayPoolEventSource.BufferAllocatedReason.PoolExhausted);
177 }
178 return array;
179 }

References System.Buffers.ConfigurableArrayPool< T >._buckets, System.Buffers.ConfigurableArrayPool< T >.Bucket._bufferLength, System.array, System.Buffers.ArrayPoolEventSource.BufferAllocated(), System.Buffers.ArrayPoolEventSource.BufferRented(), System.Buffers.ConfigurableArrayPool< T >.Bucket.Id, System.Buffers.ConfigurableArrayPool< T >.Id, System.Diagnostics.Tracing.EventSource.IsEnabled(), System.Buffers.ArrayPoolEventSource.Log, System.Buffers.ConfigurableArrayPool< T >.Bucket.Rent(), and System.Buffers.Utilities.SelectBucketIndex().