summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTarek Mahmoud Sayed <tarekms@microsoft.com>2019-03-22 15:22:50 -0700
committerGitHub <noreply@github.com>2019-03-22 15:22:50 -0700
commit39b1b6338015c9d6ef193986e0579f0ae0e60566 (patch)
treeb0e62477ba29700fbf7879aad8f830a91a02d860
parenta63da9e80defe0187d8ee59b9732a978ce4c493e (diff)
downloadcoreclr-39b1b6338015c9d6ef193986e0579f0ae0e60566.tar.gz
coreclr-39b1b6338015c9d6ef193986e0579f0ae0e60566.tar.bz2
coreclr-39b1b6338015c9d6ef193986e0579f0ae0e60566.zip
Apply Optimization in Index.GetOffset suggested by Levi (#23349)
* Apply Optimization in Index.GetOffset suggested by Levi * Add Comment * address the feedback
-rw-r--r--src/System.Private.CoreLib/shared/System/Index.cs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Index.cs b/src/System.Private.CoreLib/shared/System/Index.cs
index 9767b981ef..62d7f3440c 100644
--- a/src/System.Private.CoreLib/shared/System/Index.cs
+++ b/src/System.Private.CoreLib/shared/System/Index.cs
@@ -103,13 +103,15 @@ namespace System
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetOffset(int length)
{
- int offset;
-
+ int offset = _value;
if (IsFromEnd)
- offset = length - (~_value);
- else
- offset = _value;
+ {
+ // offset = length - (~value)
+ // offset = length + (~(~value) + 1)
+ // offset = length + value + 1
+ offset += length + 1;
+ }
return offset;
}