Skip to content

Commit f6da33f

Browse files
committed
Address PR feedback
1 parent b87524b commit f6da33f

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/libraries/System.Console/src/System/Console.cs

+10-23
Original file line numberDiff line numberDiff line change
@@ -235,23 +235,16 @@ static TextWriter EnsureInitialized()
235235

236236
private static TextWriter CreateOutputWriter(Stream outputStream)
237237
{
238-
if (outputStream == Stream.Null)
239-
return TextWriter.Null;
240-
241-
StreamWriter writer = new StreamWriter(
242-
stream: outputStream,
243-
encoding: OutputEncoding.RemovePreamble(), // This ensures no prefix is written to the stream.
244-
bufferSize: WriteBufferSize,
245-
leaveOpen: true
246-
) {
247-
AutoFlush = true
248-
};
249-
250-
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
251-
return writer;
252-
#else
253-
return TextWriter.Synchronized(writer);
254-
#endif
238+
return outputStream == Stream.Null ?
239+
TextWriter.Null :
240+
TextWriter.Synchronized(new StreamWriter(
241+
stream: outputStream,
242+
encoding: OutputEncoding.RemovePreamble(), // This ensures no prefix is written to the stream.
243+
bufferSize: WriteBufferSize,
244+
leaveOpen: true)
245+
{
246+
AutoFlush = true
247+
});
255248
}
256249

257250
private static StrongBox<bool>? _isStdInRedirected;
@@ -709,10 +702,7 @@ public static void SetOut(TextWriter newOut)
709702
// are nops.
710703
if (newOut != TextWriter.Null)
711704
{
712-
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
713-
#else
714705
newOut = TextWriter.Synchronized(newOut);
715-
#endif
716706
}
717707

718708
lock (s_syncObject)
@@ -729,10 +719,7 @@ public static void SetError(TextWriter newError)
729719
// Ensure all access to the writer is synchronized. See comment in SetOut.
730720
if (newError != TextWriter.Null)
731721
{
732-
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
733-
#else
734722
newError = TextWriter.Synchronized(newError);
735-
#endif
736723
}
737724

738725
lock (s_syncObject)

src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs

+4
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,11 @@ public static TextWriter Synchronized(TextWriter writer)
737737
{
738738
ArgumentNullException.ThrowIfNull(writer);
739739

740+
#if !TARGET_BROWSER || FEATURE_WASM_MANAGED_THREADS
740741
return writer is SyncTextWriter ? writer : new SyncTextWriter(writer);
742+
#else
743+
return writer;
744+
#endif
741745
}
742746

743747
internal sealed class SyncTextWriter : TextWriter, IDisposable

0 commit comments

Comments
 (0)