Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 22, 2024
1 parent b87524b commit f6da33f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/libraries/System.Console/src/System/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,16 @@ static TextWriter EnsureInitialized()

private static TextWriter CreateOutputWriter(Stream outputStream)
{
if (outputStream == Stream.Null)
return TextWriter.Null;

StreamWriter writer = new StreamWriter(
stream: outputStream,
encoding: OutputEncoding.RemovePreamble(), // This ensures no prefix is written to the stream.
bufferSize: WriteBufferSize,
leaveOpen: true
) {
AutoFlush = true
};

#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
return writer;
#else
return TextWriter.Synchronized(writer);
#endif
return outputStream == Stream.Null ?
TextWriter.Null :
TextWriter.Synchronized(new StreamWriter(
stream: outputStream,
encoding: OutputEncoding.RemovePreamble(), // This ensures no prefix is written to the stream.
bufferSize: WriteBufferSize,
leaveOpen: true)
{
AutoFlush = true
});
}

private static StrongBox<bool>? _isStdInRedirected;
Expand Down Expand Up @@ -709,10 +702,7 @@ public static void SetOut(TextWriter newOut)
// are nops.
if (newOut != TextWriter.Null)
{
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
#else
newOut = TextWriter.Synchronized(newOut);
#endif
}

lock (s_syncObject)
Expand All @@ -729,10 +719,7 @@ public static void SetError(TextWriter newError)
// Ensure all access to the writer is synchronized. See comment in SetOut.
if (newError != TextWriter.Null)
{
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
#else
newError = TextWriter.Synchronized(newError);
#endif
}

lock (s_syncObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,11 @@ public static TextWriter Synchronized(TextWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);

#if !TARGET_BROWSER || FEATURE_WASM_MANAGED_THREADS
return writer is SyncTextWriter ? writer : new SyncTextWriter(writer);
#else
return writer;
#endif
}

internal sealed class SyncTextWriter : TextWriter, IDisposable
Expand Down

0 comments on commit f6da33f

Please sign in to comment.