From 4868cee9cf92315f85b830acfda33625fdd236f3 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 15 Nov 2016 17:29:05 -0800 Subject: [PATCH] Remove over-optimization in NativeCommandProcessor.DequeueProcessOutput --- .../engine/NativeCommandProcessor.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index dd1d36e20b..937134ad56 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -606,19 +606,9 @@ namespace System.Management.Automation { if (blocking) { - // If adding was completed and collection is empty, - // there is no need to do a blocking Take(). - if (_nativeProcessOutputQueue.IsAddingCompleted) - { - if (_nativeProcessOutputQueue.Count > 0) - { - // This is a common codepath and although it has a duplicated code, - // we are keeping it outside of try {} catch {} to improve the perf - // for the common case. - return _nativeProcessOutputQueue.Take(); - } - } - else + // If adding was completed and collection is empty (IsCompleted == true) + // there is no need to do a blocking Take(), we should just return. + if (!_nativeProcessOutputQueue.IsCompleted) { try { @@ -635,7 +625,6 @@ namespace System.Management.Automation } } - // collection is empty return null; } else