File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/PooledObjects Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -255,15 +255,19 @@ public void SetCapacityIfLarger(int value)
255
255
{
256
256
if ( value > Capacity )
257
257
{
258
+ // For pooled arrays, we prefer exponential growth minimize the number of times
259
+ // the internal array has to be resized.
260
+ var newCapacity = Math . Max ( value , Capacity * 2 ) ;
261
+
258
262
if ( TryGetBuilder ( out var builder ) )
259
263
{
260
- Debug . Assert ( value > builder . Capacity ) ;
261
- builder . Capacity = value ;
264
+ Debug . Assert ( newCapacity > builder . Capacity ) ;
265
+ builder . Capacity = newCapacity ;
262
266
}
263
267
else
264
268
{
265
- Debug . Assert ( value > ( _capacity ?? InlineCapacity ) ) ;
266
- _capacity = value ;
269
+ Debug . Assert ( newCapacity > ( _capacity ?? InlineCapacity ) ) ;
270
+ _capacity = newCapacity ;
267
271
}
268
272
}
269
273
}
You can’t perform that action at this time.
0 commit comments