diff options
Diffstat (limited to 'src/System.Private.CoreLib/src/System/Array.cs')
-rw-r--r-- | src/System.Private.CoreLib/src/System/Array.cs | 112 |
1 files changed, 64 insertions, 48 deletions
diff --git a/src/System.Private.CoreLib/src/System/Array.cs b/src/System.Private.CoreLib/src/System/Array.cs index 12412a28f..d30a072d8 100644 --- a/src/System.Private.CoreLib/src/System/Array.cs +++ b/src/System.Private.CoreLib/src/System/Array.cs @@ -80,7 +80,7 @@ namespace System bool IList.IsReadOnly { get { return false; } } - Object IList.this[int index] + object IList.this[int index] { get { @@ -93,12 +93,12 @@ namespace System } } - int IList.Add(Object value) + int IList.Add(object value) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } - bool IList.Contains(Object value) + bool IList.Contains(object value) { return Array.IndexOf(this, value) >= 0; } @@ -108,17 +108,17 @@ namespace System Array.Clear(this, GetLowerBound(0), this.Length); } - int IList.IndexOf(Object value) + int IList.IndexOf(object value) { return Array.IndexOf(this, value); } - void IList.Insert(int index, Object value) + void IList.Insert(int index, object value) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } - void IList.Remove(Object value) + void IList.Remove(object value) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } @@ -146,12 +146,12 @@ namespace System // Make a new array which is a deep copy of the original array. // - public Object Clone() + public object Clone() { return MemberwiseClone(); } - Int32 IStructuralComparable.CompareTo(Object other, IComparer comparer) + int IStructuralComparable.CompareTo(object other, IComparer comparer) { if (other == null) { @@ -180,14 +180,14 @@ namespace System return c; } - Boolean IStructuralEquatable.Equals(Object other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) { if (other == null) { return false; } - if (Object.ReferenceEquals(this, other)) + if (object.ReferenceEquals(this, other)) { return true; } @@ -249,7 +249,7 @@ namespace System // negative result to produce the index of the first element (if any) that // is larger than the given search value. // - public static int BinarySearch(Array array, Object value) + public static int BinarySearch(Array array, object value) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -274,7 +274,7 @@ namespace System public static void Copy(Array sourceArray, Array destinationArray, long length) { - if (length > Int32.MaxValue || length < Int32.MinValue) + if (length > int.MaxValue || length < int.MinValue) throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_HugeArrayNotSupported); Array.Copy(sourceArray, destinationArray, (int)length); @@ -282,11 +282,11 @@ namespace System public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length) { - if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) + if (sourceIndex > int.MaxValue || sourceIndex < int.MinValue) throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_HugeArrayNotSupported); - if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue) + if (destinationIndex > int.MaxValue || destinationIndex < int.MinValue) throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.ArgumentOutOfRange_HugeArrayNotSupported); - if (length > Int32.MaxValue || length < Int32.MinValue) + if (length > int.MaxValue || length < int.MinValue) throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_HugeArrayNotSupported); Array.Copy(sourceArray, (int)sourceIndex, destinationArray, (int)destinationIndex, (int)length); @@ -294,7 +294,7 @@ namespace System public void CopyTo(Array array, long index) { - if (index > Int32.MaxValue || index < Int32.MinValue) + if (index > int.MaxValue || index < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_HugeArrayNotSupported); this.CopyTo(array, (int)index); @@ -336,37 +336,37 @@ namespace System return GetLength(dimension); } - public Object GetValue(long index) + public object GetValue(long index) { - if (index > Int32.MaxValue || index < Int32.MinValue) + if (index > int.MaxValue || index < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_HugeArrayNotSupported); return this.GetValue((int)index); } - public Object GetValue(long index1, long index2) + public object GetValue(long index1, long index2) { - if (index1 > Int32.MaxValue || index1 < Int32.MinValue) + if (index1 > int.MaxValue || index1 < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index1), SR.ArgumentOutOfRange_HugeArrayNotSupported); - if (index2 > Int32.MaxValue || index2 < Int32.MinValue) + if (index2 > int.MaxValue || index2 < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index2), SR.ArgumentOutOfRange_HugeArrayNotSupported); return this.GetValue((int)index1, (int)index2); } - public Object GetValue(long index1, long index2, long index3) + public object GetValue(long index1, long index2, long index3) { - if (index1 > Int32.MaxValue || index1 < Int32.MinValue) + if (index1 > int.MaxValue || index1 < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index1), SR.ArgumentOutOfRange_HugeArrayNotSupported); - if (index2 > Int32.MaxValue || index2 < Int32.MinValue) + if (index2 > int.MaxValue || index2 < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index2), SR.ArgumentOutOfRange_HugeArrayNotSupported); - if (index3 > Int32.MaxValue || index3 < Int32.MinValue) + if (index3 > int.MaxValue || index3 < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index3), SR.ArgumentOutOfRange_HugeArrayNotSupported); return this.GetValue((int)index1, (int)index2, (int)index3); } - public Object GetValue(params long[] indices) + public object GetValue(params long[] indices) { if (indices == null) throw new ArgumentNullException(nameof(indices)); @@ -378,7 +378,7 @@ namespace System for (int i = 0; i < indices.Length; ++i) { long index = indices[i]; - if (index > Int32.MaxValue || index < Int32.MinValue) + if (index > int.MaxValue || index < int.MinValue) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_HugeArrayNotSupported); intIndices[i] = (int)index; } @@ -398,7 +398,7 @@ namespace System // Returns an object appropriate for synchronizing access to this // Array. - public Object SyncRoot { get { return this; } } + public object SyncRoot { get { return this; } } // Searches a section of an array for a given element using a binary search // algorithm. Elements of the array are compared to the search value using @@ -413,7 +413,7 @@ namespace System // negative result to produce the index of the first element (if any) that // is larger than the given search value. // - public static int BinarySearch(Array array, int index, int length, Object value) + public static int BinarySearch(Array array, int index, int length, object value) { return BinarySearch(array, index, length, value, null); } @@ -432,7 +432,7 @@ namespace System // negative result to produce the index of the first element (if any) that // is larger than the given search value. // - public static int BinarySearch(Array array, Object value, IComparer comparer) + public static int BinarySearch(Array array, object value, IComparer comparer) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -454,7 +454,7 @@ namespace System // negative result to produce the index of the first element (if any) that // is larger than the given search value. // - public static int BinarySearch(Array array, int index, int length, Object value, IComparer comparer) + public static int BinarySearch(Array array, int index, int length, object value, IComparer comparer) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -470,7 +470,7 @@ namespace System int lo = index; int hi = index + length - 1; - Object[] objArray = array as Object[]; + object[] objArray = array as object[]; if (objArray != null) { while (lo <= hi) @@ -561,14 +561,14 @@ namespace System if (array.Length - index < length) throw new ArgumentException(SR.Argument_InvalidOffLen); - return ArraySortHelper<T>.BinarySearch(array, index, length, value, comparer); + return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer); } // Returns the index of the first occurrence of a given value in an array. // The array is searched forwards, and the elements of the array are // compared to the given value using the Object.Equals method. // - public static int IndexOf(Array array, Object value) + public static int IndexOf(Array array, object value) { if (array == null) { @@ -584,7 +584,7 @@ namespace System // elements of the array are compared to the given value using the // Object.Equals method. // - public static int IndexOf(Array array, Object value, int startIndex) + public static int IndexOf(Array array, object value, int startIndex) { if (array == null) { @@ -601,7 +601,7 @@ namespace System // elements of the array are compared to the given value using the // Object.Equals method. // - public static int IndexOf(Array array, Object value, int startIndex, int count) + public static int IndexOf(Array array, object value, int startIndex, int count) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -613,7 +613,7 @@ namespace System if (count < 0 || count > array.Length - startIndex + lb) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); - Object[] objArray = array as Object[]; + object[] objArray = array as object[]; int endIndex = startIndex + count; if (objArray != null) { @@ -628,7 +628,7 @@ namespace System { for (int i = startIndex; i < endIndex; i++) { - Object obj = objArray[i]; + object obj = objArray[i]; if (obj != null && obj.Equals(value)) return i; } } @@ -637,7 +637,7 @@ namespace System { for (int i = startIndex; i < endIndex; i++) { - Object obj = array.GetValue(i); + object obj = array.GetValue(i); if (obj == null) { if (value == null) return i; @@ -696,7 +696,7 @@ namespace System return IndexOfImpl(array, value, startIndex, count); } - public static int LastIndexOf(Array array, Object value) + public static int LastIndexOf(Array array, object value) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -709,7 +709,7 @@ namespace System // startIndex and ending at index 0. The elements of the array are // compared to the given value using the Object.Equals method. // - public static int LastIndexOf(Array array, Object value, int startIndex) + public static int LastIndexOf(Array array, object value, int startIndex) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -723,7 +723,7 @@ namespace System // the array are compared to the given value using the Object.Equals // method. // - public static int LastIndexOf(Array array, Object value, int startIndex, int count) + public static int LastIndexOf(Array array, object value, int startIndex, int count) { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -742,7 +742,7 @@ namespace System if (array.Rank != 1) throw new RankException(SR.Rank_MultiDimNotSupported); - Object[] objArray = array as Object[]; + object[] objArray = array as object[]; int endIndex = startIndex - count + 1; if (objArray != null) { @@ -757,7 +757,7 @@ namespace System { for (int i = startIndex; i >= endIndex; i--) { - Object obj = objArray[i]; + object obj = objArray[i]; if (obj != null && obj.Equals(value)) return i; } } @@ -766,7 +766,7 @@ namespace System { for (int i = startIndex; i >= endIndex; i--) { - Object obj = array.GetValue(i); + object obj = array.GetValue(i); if (obj == null) { if (value == null) return i; @@ -873,7 +873,7 @@ namespace System if (array.Rank != 1) throw new RankException(SR.Rank_MultiDimNotSupported); - Object[] objArray = array as Object[]; + object[] objArray = array as object[]; if (objArray != null) { Array.Reverse<object>(objArray, index, length); @@ -884,7 +884,7 @@ namespace System int j = index + length - 1; while (i < j) { - Object temp = array.GetValue(i); + object temp = array.GetValue(i); array.SetValue(array.GetValue(j), i); array.SetValue(temp, j); i++; @@ -910,6 +910,10 @@ namespace System if (array.Length - index < length) throw new ArgumentException(SR.Argument_InvalidOffLen); + if (length <= 1) + return; + +#if __MonoCS__ ref T p = ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()); int i = index; int j = index + length - 1; @@ -921,6 +925,18 @@ namespace System i++; j--; } +#else + ref T first = ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), index); + ref T last = ref Unsafe.Add(ref Unsafe.Add(ref first, length), -1); + do + { + T temp = first; + first = last; + last = temp; + first = ref Unsafe.Add(ref first, 1); + last = ref Unsafe.Add(ref last, -1); + } while (Unsafe.IsAddressLessThan(ref first, ref last)); +#endif } public void SetValue(object value, long index) @@ -1094,7 +1110,7 @@ namespace System throw new ArgumentException(SR.Argument_InvalidOffLen); if (length > 1) - ArraySortHelper<T>.Sort(array, index, length, comparer); + ArraySortHelper<T>.Default.Sort(array, index, length, comparer); } public static void Sort<T>(T[] array, Comparison<T> comparison) |