Remove one virtual call from StreamHelpers.ValidateCopyToArgs (dotnet/coreclr#8361)
authorAndy Ayers <andya@microsoft.com>
Wed, 30 Nov 2016 03:00:26 +0000 (19:00 -0800)
committerJan Kotas <jkotas@microsoft.com>
Wed, 30 Nov 2016 03:00:26 +0000 (19:00 -0800)
Check CanWrite on the destination stream first.

In the common case CanWrite is true, and CanRead is only needed to
determine which kind of exception to throw when CanWrite is false.

Commit migrated from https://github.com/dotnet/coreclr/commit/85a1a1d4e981e184f2f5d91c41a4d3be2a4ea3fa

src/coreclr/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs

index 6cce13d..8ff0e04 100644 (file)
@@ -27,7 +27,7 @@ namespace System.IO
             }
 
             bool destinationCanWrite = destination.CanWrite;
-            if (!destination.CanRead && !destinationCanWrite)
+            if (!destinationCanWrite && !destination.CanRead)
             {
                 throw new ObjectDisposedException(nameof(destination), Environment.GetResourceString("ObjectDisposed_StreamClosed"));
             }