File tree Expand file tree Collapse file tree
src/libraries/System.Private.CoreLib/src/System/Buffers Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments