Skip to content

Commit c1c77cb

Browse files
committed
Remove useless Disposable field
1 parent 0220268 commit c1c77cb

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryDefaultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected internal override bool OnWriteResume(
2828
if (state.Current.CollectionEnumerator == null)
2929
{
3030
enumerator = value.GetEnumerator();
31-
state.Current.Disposable = enumerator;
31+
state.Current.CollectionEnumerator = enumerator;
3232
if (!enumerator.MoveNext())
3333
{
3434
enumerator.Dispose();

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected internal override bool OnWriteResume(
3232
if (state.Current.CollectionEnumerator == null)
3333
{
3434
enumerator = value.GetEnumerator();
35-
state.Current.Disposable = enumerator;
35+
state.Current.CollectionEnumerator = enumerator;
3636
if (!enumerator.MoveNext())
3737
{
3838
enumerator.Dispose();

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableDefaultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected override bool OnWriteResume(Utf8JsonWriter writer, TCollection value,
2222
if (state.Current.CollectionEnumerator == null)
2323
{
2424
enumerator = value.GetEnumerator();
25-
state.Current.Disposable = enumerator;
25+
state.Current.CollectionEnumerator = enumerator;
2626
if (!enumerator.MoveNext())
2727
{
2828
enumerator.Dispose();

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -309,31 +309,27 @@ public void DisposePendingDisposablesOnException()
309309
Exception? exception = null;
310310

311311
Debug.Assert(Current.AsyncDisposable is null);
312-
DisposeFrame(Current.CollectionEnumerator, Current.Disposable, ref exception);
312+
DisposeFrame(Current.CollectionEnumerator, ref exception);
313313

314314
int stackSize = Math.Max(_count, _continuationCount);
315315
for (int i = 0; i < stackSize - 1; i++)
316316
{
317317
Debug.Assert(_stack[i].AsyncDisposable is null);
318-
DisposeFrame(_stack[i].CollectionEnumerator, _stack[i].Disposable, ref exception);
318+
DisposeFrame(_stack[i].CollectionEnumerator, ref exception);
319319
}
320320

321321
if (exception is not null)
322322
{
323323
ExceptionDispatchInfo.Capture(exception).Throw();
324324
}
325325

326-
static void DisposeFrame(IEnumerator? collectionEnumerator, IDisposable? disposable, ref Exception? exception)
326+
static void DisposeFrame(IEnumerator? collectionEnumerator, ref Exception? exception)
327327
{
328328
try
329329
{
330-
if (collectionEnumerator is IDisposable disposableEnumerator)
330+
if (collectionEnumerator is IDisposable disposable)
331331
{
332-
disposableEnumerator.Dispose();
333-
}
334-
else
335-
{
336-
disposable?.Dispose();
332+
disposable.Dispose();
337333
}
338334
}
339335
catch (Exception e)
@@ -351,37 +347,33 @@ public async ValueTask DisposePendingDisposablesOnExceptionAsync()
351347
{
352348
Exception? exception = null;
353349

354-
exception = await DisposeFrame(Current.CollectionEnumerator, Current.AsyncDisposable, Current.Disposable, exception).ConfigureAwait(false);
350+
exception = await DisposeFrame(Current.CollectionEnumerator, Current.AsyncDisposable, exception).ConfigureAwait(false);
355351

356352
int stackSize = Math.Max(_count, _continuationCount);
357353
for (int i = 0; i < stackSize - 1; i++)
358354
{
359-
exception = await DisposeFrame(_stack[i].CollectionEnumerator, _stack[i].AsyncDisposable, _stack[i].Disposable, exception).ConfigureAwait(false);
355+
exception = await DisposeFrame(_stack[i].CollectionEnumerator, _stack[i].AsyncDisposable, exception).ConfigureAwait(false);
360356
}
361357

362358
if (exception is not null)
363359
{
364360
ExceptionDispatchInfo.Capture(exception).Throw();
365361
}
366362

367-
static async ValueTask<Exception?> DisposeFrame(IEnumerator? collectionEnumerator, IAsyncDisposable? asyncDisposable, IDisposable? disposable, Exception? exception)
363+
static async ValueTask<Exception?> DisposeFrame(IEnumerator? collectionEnumerator, IAsyncDisposable? asyncDisposable, Exception? exception)
368364
{
369365
Debug.Assert(!(collectionEnumerator is not null && asyncDisposable is not null));
370366

371367
try
372368
{
373-
if (collectionEnumerator is IDisposable disposableEnumerator)
369+
if (collectionEnumerator is IDisposable disposable)
374370
{
375-
disposableEnumerator.Dispose();
371+
disposable.Dispose();
376372
}
377373
else if (asyncDisposable is not null)
378374
{
379375
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
380376
}
381-
else
382-
{
383-
disposable?.Dispose();
384-
}
385377
}
386378
catch (Exception e)
387379
{

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ internal struct WriteStackFrame
1818
/// </summary>
1919
public IEnumerator? CollectionEnumerator;
2020

21-
/// <summary>
22-
/// The enumerator for resumable disposables.
23-
/// </summary>
24-
public IDisposable? Disposable;
25-
2621
/// <summary>
2722
/// The enumerator for resumable async disposables.
2823
/// </summary>

0 commit comments

Comments
 (0)