diff options
author | James Ko <jamesqko@gmail.com> | 2016-05-17 11:46:08 -0400 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-05-17 08:46:08 -0700 |
commit | ee683a09634c967240bd63b3c925d6a99e0ac014 (patch) | |
tree | 8fb84558648c8b136fbc04f6f339be7e9634f52f | |
parent | 1cb362e337c062a6f5945e6c8afd18b6830aeb75 (diff) | |
download | coreclr-ee683a09634c967240bd63b3c925d6a99e0ac014.tar.gz coreclr-ee683a09634c967240bd63b3c925d6a99e0ac014.tar.bz2 coreclr-ee683a09634c967240bd63b3c925d6a99e0ac014.zip |
Optimize Array.GetLength, GetUpperBound, GetLowerBound (#4993)
... if the argument is 0. As the rank will always be greater, this is safe.
-rw-r--r-- | src/classlibnative/bcltype/arraynative.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/classlibnative/bcltype/arraynative.cpp b/src/classlibnative/bcltype/arraynative.cpp index 3f3b2b72f0..c98eaf8b69 100644 --- a/src/classlibnative/bcltype/arraynative.cpp +++ b/src/classlibnative/bcltype/arraynative.cpp @@ -39,13 +39,15 @@ FCIMPL2(INT32, ArrayNative::GetLowerBound, ArrayBase* array, unsigned int dimens if (array == NULL) FCThrow(kNullReferenceException); - - // What is this an array of? - MethodTable *pArrayMT = array->GetMethodTable(); - DWORD Rank = pArrayMT->GetRank(); - - if (dimension >= Rank) - FCThrowRes(kIndexOutOfRangeException, W("IndexOutOfRange_ArrayRankIndex")); + + if (dimension != 0) + { + // Check the dimension is within our rank + unsigned int rank = array->GetRank(); + + if (dimension >= rank) + FCThrowRes(kIndexOutOfRangeException, W("IndexOutOfRange_ArrayRankIndex")); + } return array->GetLowerBoundsPtr()[dimension]; } @@ -61,13 +63,15 @@ FCIMPL2(INT32, ArrayNative::GetUpperBound, ArrayBase* array, unsigned int dimens if (array == NULL) FCThrow(kNullReferenceException); - - // What is this an array of? - MethodTable *pArrayMT = array->GetMethodTable(); - DWORD Rank = pArrayMT->GetRank(); - - if (dimension >= Rank) - FCThrowRes(kIndexOutOfRangeException, W("IndexOutOfRange_ArrayRankIndex")); + + if (dimension != 0) + { + // Check the dimension is within our rank + unsigned int rank = array->GetRank(); + + if (dimension >= rank) + FCThrowRes(kIndexOutOfRangeException, W("IndexOutOfRange_ArrayRankIndex")); + } return array->GetBoundsPtr()[dimension] + array->GetLowerBoundsPtr()[dimension] - 1; } @@ -82,9 +86,15 @@ FCIMPL2(INT32, ArrayNative::GetLength, ArrayBase* array, unsigned int dimension) if (array==NULL) FCThrow(kNullReferenceException); - unsigned int rank = array->GetRank(); - if (dimension >= rank) - FCThrow(kIndexOutOfRangeException); + + if (dimension != 0) + { + // Check the dimension is within our rank + unsigned int rank = array->GetRank(); + if (dimension >= rank) + FCThrow(kIndexOutOfRangeException); + } + return array->GetBoundsPtr()[dimension]; } FCIMPLEND |