Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 109063a

Browse files
committed
Clean up some dead code in SyncTextReader/Writer
1 parent 57b0c2c commit 109063a

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

src/System.Console/src/System/IO/SyncTextReader.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,23 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
5-
using System.IO;
6-
using System.Text;
7-
using System.Threading;
8-
using System.Threading.Tasks;
9-
using System.Runtime.CompilerServices;
10-
using System.Runtime.InteropServices;
11-
using System.Globalization;
12-
using System.Diagnostics.CodeAnalysis;
4+
using System.Diagnostics;
135
using System.Diagnostics.Contracts;
6+
using System.Runtime.InteropServices;
7+
using System.Threading.Tasks;
148

159
namespace System.IO
1610
{
1711
internal sealed class SyncTextReader : TextReader
1812
{
19-
internal TextReader _in;
13+
private readonly TextReader _in;
2014
private readonly object _methodLock = new object();
2115

22-
public static TextReader GetSynchronizedTextReader(TextReader reader)
16+
public static SyncTextReader GetSynchronizedTextReader(TextReader reader)
2317
{
24-
if (reader == null)
25-
throw new ArgumentNullException("reader");
26-
Contract.Ensures(Contract.Result<TextReader>() != null);
27-
Contract.EndContractBlock();
28-
29-
if (reader is SyncTextReader)
30-
return reader;
31-
32-
return new SyncTextReader(reader);
18+
Debug.Assert(reader != null);
19+
return reader as SyncTextReader ??
20+
new SyncTextReader(reader);
3321
}
3422

3523
internal SyncTextReader(TextReader t)

src/System.Console/src/System/IO/SyncTextWriter.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System.Diagnostics.CodeAnalysis;
5-
using System.Diagnostics.Contracts;
6-
using System.Runtime.InteropServices;
4+
using System.Diagnostics;
75
using System.Text;
86
using System.Threading.Tasks;
97

@@ -14,15 +12,10 @@ internal sealed class SyncTextWriter : TextWriter, IDisposable
1412
private readonly object _methodLock = new object();
1513
internal readonly TextWriter _out;
1614

17-
internal static TextWriter GetSynchronizedTextWriter(TextWriter writer)
15+
internal static SyncTextWriter GetSynchronizedTextWriter(TextWriter writer)
1816
{
19-
if (writer == null)
20-
throw new ArgumentNullException("writer");
21-
Contract.Ensures(Contract.Result<TextWriter>() != null);
22-
Contract.EndContractBlock();
23-
24-
return writer is SyncTextWriter ?
25-
writer :
17+
Debug.Assert(writer != null);
18+
return writer as SyncTextWriter ??
2619
new SyncTextWriter(writer);
2720
}
2821

0 commit comments

Comments
 (0)