From 424f16bdb3fc3ce0e49adb25ee6b3dfe45883c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Wed, 20 Jul 2022 20:53:02 +0200 Subject: [PATCH] Don't use trick for collapsed epilogs Cf. https://github.com/dotnet/runtime/pull/67049#discussion_r833689895 --- .../src/System/String.Manipulation.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs index 1f73093302f0e..6e6bd40b1d48b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs @@ -986,11 +986,13 @@ private string ReplaceCore(string oldValue, string? newValue, CompareInfo? ci, C // public string Replace(char oldChar, char newChar) { - int firstIndex; - if (oldChar == newChar || (firstIndex = IndexOf(oldChar)) < 0) - { + if (oldChar == newChar) + return this; + + int firstIndex = IndexOf(oldChar); + + if (firstIndex < 0) return this; - } int remainingLength = Length - firstIndex; string result = FastAllocateString(Length);