From 8a17a2bd9ba357eacf1fd89f616c668816fedc64 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sat, 31 Dec 2022 21:32:20 +0500 Subject: [PATCH 1/6] Fast return if progress message does not start with GUID --- .../engine/hostifaces/HostUtilities.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index c543ad11f13..dc9a92115e4 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -522,8 +522,18 @@ internal static string RemoveGuidFromMessage(string message, out bool matchPatte internal static string RemoveIdentifierInfoFromMessage(string message, out bool matchPattern) { matchPattern = false; - if (string.IsNullOrEmpty(message)) + if (message is null || + message.Length < 36 || + message[33] != '[' || + message[32] != ':' || + message[20] != '-' || + message[16] != '-' || + message[12] != '-' || + message[8] != '-') + { + // Fast return if the message does not start with 'GUID:[]:'. return message; + } const string pattern = @"^([\d\w]{8}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{12}:\[.*\]:).*"; Match matchResult = Regex.Match(message, pattern); From 69873344ae8d51ec25d606c4e32ef2daeeb34055 Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 2 Jan 2023 21:10:19 +0500 Subject: [PATCH 2/6] Fix indexes --- .../engine/hostifaces/HostUtilities.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index dc9a92115e4..063437bec68 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -523,12 +523,12 @@ internal static string RemoveIdentifierInfoFromMessage(string message, out bool { matchPattern = false; if (message is null || - message.Length < 36 || - message[33] != '[' || - message[32] != ':' || - message[20] != '-' || - message[16] != '-' || - message[12] != '-' || + message.Length < 40 || + message[37] != '[' || + message[36] != ':' || + message[23] != '-' || + message[18] != '-' || + message[13] != '-' || message[8] != '-') { // Fast return if the message does not start with 'GUID:[]:'. From c957eb548af7607e62ba5fc5381001accbfa7e86 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 5 Jan 2023 20:43:41 +0500 Subject: [PATCH 3/6] Fast return if other messages don't start with GUID --- .../engine/hostifaces/HostUtilities.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index 063437bec68..9f17b35a386 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -504,8 +504,17 @@ internal static List GetSuggestion(HistoryInfo lastHistory, object lastE internal static string RemoveGuidFromMessage(string message, out bool matchPattern) { matchPattern = false; - if (string.IsNullOrEmpty(message)) + if (message is null || + message.Length < 37 || + message[36] != ':' || + message[23] != '-' || + message[18] != '-' || + message[13] != '-' || + message[8] != '-') + { + // Fast return if the message does not start with 'GUID:'. return message; + } const string pattern = @"^([\d\w]{8}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{12}:).*"; Match matchResult = Regex.Match(message, pattern); From 5b5ec553933b98e32f115fee481fad050c3d70aa Mon Sep 17 00:00:00 2001 From: Ilya Date: Sat, 7 Jan 2023 10:28:36 +0500 Subject: [PATCH 4/6] Remove unused out parameter --- .../engine/hostifaces/HostUtilities.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index 9f17b35a386..dc8a8f91fc3 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -499,11 +499,9 @@ internal static List GetSuggestion(HistoryInfo lastHistory, object lastE /// Remove the GUID from the message if the message is in the pre-defined format. /// /// - /// /// - internal static string RemoveGuidFromMessage(string message, out bool matchPattern) + internal static string RemoveGuidFromMessage(string message) { - matchPattern = false; if (message is null || message.Length < 37 || message[36] != ':' || @@ -522,7 +520,6 @@ internal static string RemoveGuidFromMessage(string message, out bool matchPatte { string partToRemove = matchResult.Groups[1].Captures[0].Value; message = message.Remove(0, partToRemove.Length); - matchPattern = true; } return message; From 9b442c04eb06e7695facce598d10636ce4583b56 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sat, 7 Jan 2023 11:35:47 +0500 Subject: [PATCH 5/6] Remove unused out parameter 2 --- .../host/msh/ConsoleHostUserInterface.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index d755e042984..81dc6f70a67 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1207,7 +1207,7 @@ internal string WrapToCurrentWindowWidth(string text) public override void WriteDebugLine(string message) { // don't lock here as WriteLine is already protected. - message = HostUtilities.RemoveGuidFromMessage(message, out _); + message = HostUtilities.RemoveGuidFromMessage(message); // We should write debug to error stream only if debug is redirected.) if (_parent.ErrorFormat == Serialization.DataFormat.XML) @@ -1267,7 +1267,7 @@ public override void WriteInformation(InformationRecord record) public override void WriteVerboseLine(string message) { // don't lock here as WriteLine is already protected. - message = HostUtilities.RemoveGuidFromMessage(message, out _); + message = HostUtilities.RemoveGuidFromMessage(message); // NTRAID#Windows OS Bugs-1061752-2004/12/15-sburns should read a skin setting here...) if (_parent.ErrorFormat == Serialization.DataFormat.XML) @@ -1310,7 +1310,7 @@ public override void WriteVerboseLine(string message) public override void WriteWarningLine(string message) { // don't lock here as WriteLine is already protected. - message = HostUtilities.RemoveGuidFromMessage(message, out _); + message = HostUtilities.RemoveGuidFromMessage(message); // NTRAID#Windows OS Bugs-1061752-2004/12/15-sburns should read a skin setting here...) if (_parent.ErrorFormat == Serialization.DataFormat.XML) From b9bcacd97514a8850f056131fe6181859c68e8bc Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 28 Feb 2023 10:57:27 +0500 Subject: [PATCH 6/6] Remove RemoveGuidFromMessage and RemoveIdentifierInfoFromMessage --- .../host/msh/ConsoleHostUserInterface.cs | 16 ----- .../engine/hostifaces/HostUtilities.cs | 58 ------------------- 2 files changed, 74 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 81dc6f70a67..64c90e24cf7 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1206,9 +1206,6 @@ internal string WrapToCurrentWindowWidth(string text) /// public override void WriteDebugLine(string message) { - // don't lock here as WriteLine is already protected. - message = HostUtilities.RemoveGuidFromMessage(message); - // We should write debug to error stream only if debug is redirected.) if (_parent.ErrorFormat == Serialization.DataFormat.XML) { @@ -1266,9 +1263,6 @@ public override void WriteInformation(InformationRecord record) /// public override void WriteVerboseLine(string message) { - // don't lock here as WriteLine is already protected. - message = HostUtilities.RemoveGuidFromMessage(message); - // NTRAID#Windows OS Bugs-1061752-2004/12/15-sburns should read a skin setting here...) if (_parent.ErrorFormat == Serialization.DataFormat.XML) { @@ -1309,9 +1303,6 @@ public override void WriteVerboseLine(string message) /// public override void WriteWarningLine(string message) { - // don't lock here as WriteLine is already protected. - message = HostUtilities.RemoveGuidFromMessage(message); - // NTRAID#Windows OS Bugs-1061752-2004/12/15-sburns should read a skin setting here...) if (_parent.ErrorFormat == Serialization.DataFormat.XML) { @@ -1346,13 +1337,6 @@ public override void WriteProgress(long sourceId, ProgressRecord record) return; } - bool matchPattern; - string currentOperation = HostUtilities.RemoveIdentifierInfoFromMessage(record.CurrentOperation, out matchPattern); - if (matchPattern) - { - record = new ProgressRecord(record) { CurrentOperation = currentOperation }; - } - // We allow only one thread at a time to update the progress state.) if (_parent.ErrorFormat == Serialization.DataFormat.XML) { diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index dc8a8f91fc3..7c23c992a92 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -495,64 +495,6 @@ internal static List GetSuggestion(HistoryInfo lastHistory, object lastE return returnSuggestions; } - /// - /// Remove the GUID from the message if the message is in the pre-defined format. - /// - /// - /// - internal static string RemoveGuidFromMessage(string message) - { - if (message is null || - message.Length < 37 || - message[36] != ':' || - message[23] != '-' || - message[18] != '-' || - message[13] != '-' || - message[8] != '-') - { - // Fast return if the message does not start with 'GUID:'. - return message; - } - - const string pattern = @"^([\d\w]{8}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{12}:).*"; - Match matchResult = Regex.Match(message, pattern); - if (matchResult.Success) - { - string partToRemove = matchResult.Groups[1].Captures[0].Value; - message = message.Remove(0, partToRemove.Length); - } - - return message; - } - - internal static string RemoveIdentifierInfoFromMessage(string message, out bool matchPattern) - { - matchPattern = false; - if (message is null || - message.Length < 40 || - message[37] != '[' || - message[36] != ':' || - message[23] != '-' || - message[18] != '-' || - message[13] != '-' || - message[8] != '-') - { - // Fast return if the message does not start with 'GUID:[]:'. - return message; - } - - const string pattern = @"^([\d\w]{8}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{4}\-[\d\w]{12}:\[.*\]:).*"; - Match matchResult = Regex.Match(message, pattern); - if (matchResult.Success) - { - string partToRemove = matchResult.Groups[1].Captures[0].Value; - message = message.Remove(0, partToRemove.Length); - matchPattern = true; - } - - return message; - } - /// /// Create suggestion with string rule and scriptblock suggestion. ///