Skip to content

Commit d8b1b1b

Browse files
committed
Fully revert ArrayPool workaround
1 parent 59da2cc commit d8b1b1b

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,14 @@ public bool Trim()
211211
// Under high pressure, release all thread locals.
212212
if (pressure == Utilities.MemoryPressure.High)
213213
{
214-
if (log.IsEnabled())
214+
if (!log.IsEnabled())
215+
{
216+
foreach (KeyValuePair<ThreadLocalArray[], object?> tlsBuckets in _allTlsBuckets)
217+
{
218+
Array.Clear(tlsBuckets.Key);
219+
}
220+
}
221+
else
215222
{
216223
foreach (KeyValuePair<ThreadLocalArray[], object?> tlsBuckets in _allTlsBuckets)
217224
{
@@ -225,13 +232,6 @@ public bool Trim()
225232
}
226233
}
227234
}
228-
else
229-
{
230-
foreach (KeyValuePair<ThreadLocalArray[], object?> tlsBuckets in _allTlsBuckets)
231-
{
232-
Array.Clear(tlsBuckets.Key);
233-
}
234-
}
235235
}
236236
else
237237
{
@@ -266,12 +266,10 @@ public bool Trim()
266266
{
267267
// Time noticeably wrapped, or we've surpassed the threshold.
268268
// Clear out the array, and log its being trimmed if desired.
269-
if (Interlocked.Exchange(ref buckets[i].Array, null) is T[] buffer)
269+
if (Interlocked.Exchange(ref buckets[i].Array, null) is T[] buffer &&
270+
log.IsEnabled())
270271
{
271-
if (log.IsEnabled())
272-
{
273-
log.BufferTrimmed(buffer.GetHashCode(), buffer.Length, Id);
274-
}
272+
log.BufferTrimmed(buffer.GetHashCode(), buffer.Length, Id);
275273
}
276274
}
277275
}

0 commit comments

Comments
 (0)