Skip rangecheck in string.EndsWith(char) (#22206)
authorBen Adams <thundercat@illyriad.co.uk>
Fri, 25 Jan 2019 19:03:33 +0000 (20:03 +0100)
committerJan Kotas <jkotas@microsoft.com>
Fri, 25 Jan 2019 19:03:33 +0000 (11:03 -0800)
src/System.Private.CoreLib/shared/System/String.Comparison.cs

index 5bae67b..c8f0d20 100644 (file)
@@ -594,8 +594,8 @@ namespace System
 
         public bool EndsWith(char value)
         {
-            int thisLen = Length;
-            return thisLen != 0 && this[thisLen - 1] == value;
+            int lastPos = Length - 1;
+            return ((uint)lastPos < (uint)Length) && this[lastPos] == value;
         }
 
         // Determines whether two strings match.