From a751b2e846c20d9201ca9b4229036df732210ae1 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Tue, 29 Nov 2016 19:00:26 -0800 Subject: [PATCH] Remove one virtual call from StreamHelpers.ValidateCopyToArgs (dotnet/coreclr#8361) 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs b/src/coreclr/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs index 6cce13d..8ff0e04 100644 --- a/src/coreclr/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs +++ b/src/coreclr/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs @@ -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")); } -- 2.7.4