Skip to content

Commit

Permalink
Mirror changes from mono/coreclr (#17297)
Browse files Browse the repository at this point in the history
* Enable fast-paths on Mono for Array (dotnet/coreclr#27144)

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>

* [CoreLib] Remove String fields moved to shared

* Stub Array Try* methods
  • Loading branch information
Dotnet-GitSync-Bot authored and marek-safar committed Oct 12, 2019
1 parent 9832bbb commit 4e81814
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
16 changes: 8 additions & 8 deletions netcore/System.Private.CoreLib/shared/System/Array.cs
Expand Up @@ -472,7 +472,7 @@ public static int BinarySearch(Array array, int index, int length, object? value
ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);

comparer ??= Comparer.Default;
#if CORECLR
#if !CORERT
if (comparer == Comparer.Default)
{
int retval;
Expand Down Expand Up @@ -921,7 +921,7 @@ public static int IndexOf(Array array, object? value, int startIndex, int count)
if (count < 0 || count > array.Length - startIndex + lb)
ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();

#if CORECLR
#if !CORERT
// Try calling a quick native method to handle primitive types.
int retVal;
bool r = TrySZIndexOf(array, startIndex, count, value, out retVal);
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public static int IndexOf<T>(T[] array, T value, int startIndex, int count)
}
}

#if CORECLR
#if !CORERT
return EqualityComparer<T>.Default.IndexOf(array, value, startIndex, count);
#else
return IndexOfImpl(array, value, startIndex, count);
Expand Down Expand Up @@ -1104,7 +1104,7 @@ public static int LastIndexOf(Array array, object? value, int startIndex, int co
if (array.Rank != 1)
ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);

#if CORECLR
#if !CORERT
// Try calling a quick native method to handle primitive types.
int retVal;
bool r = TrySZLastIndexOf(array, startIndex, count, value, out retVal);
Expand Down Expand Up @@ -1255,7 +1255,7 @@ public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count)
}
}

#if CORECLR
#if !CORERT
return EqualityComparer<T>.Default.LastIndexOf(array, value, startIndex, count);
#else
return LastIndexOfImpl(array, value, startIndex, count);
Expand Down Expand Up @@ -1298,7 +1298,7 @@ public static void Reverse(Array array, int index, int length)
if (length <= 1)
return;

#if CORECLR
#if !CORERT
bool r = TrySZReverse(array, index, length);
if (r)
return;
Expand Down Expand Up @@ -1521,7 +1521,7 @@ public static void Sort<T>(T[] array, int index, int length, System.Collections.

if (length > 1)
{
#if CORECLR
#if !CORERT
if (comparer == null || comparer == Comparer<T>.Default)
{
if (TrySZSort(array, null, index, index + length - 1))
Expand All @@ -1548,7 +1548,7 @@ public static void Sort<T>(T[] array, int index, int length, System.Collections.

if (length > 1)
{
#if CORECLR
#if !CORERT
if (comparer == null || comparer == Comparer<TKey>.Default)
{
if (TrySZSort(keys, items, index, index + length - 1))
Expand Down
11 changes: 11 additions & 0 deletions netcore/System.Private.CoreLib/shared/System/String.cs
Expand Up @@ -33,6 +33,17 @@ public sealed partial class String : IComparable, IEnumerable, IConvertible, IEn
#nullable restore
ICloneable
{
//
// These fields map directly onto the fields in an EE StringObject. See object.h for the layout.
//
[NonSerialized]
private int _stringLength;

// For empty strings, this will be '\0' since
// strings are both null-terminated and length prefixed
[NonSerialized]
private char _firstChar;

/*
* CONSTRUCTORS
*
Expand Down
22 changes: 22 additions & 0 deletions netcore/System.Private.CoreLib/src/System/Array.cs
Expand Up @@ -424,6 +424,28 @@ static void SortImpl (Array keys, Array? items, int index, int length, IComparer
}
}

static bool TrySZBinarySearch (Array sourceArray, int sourceIndex, int count, object? value, out int retVal)
{
retVal = default;
return false;
}

static bool TrySZIndexOf (Array sourceArray, int sourceIndex, int count, object? value, out int retVal)
{
retVal = default;
return false;
}

static bool TrySZLastIndexOf (Array sourceArray, int sourceIndex, int count, object? value, out int retVal)
{
retVal = default;
return false;
}

static bool TrySZReverse (Array array, int index, int count) => false;

static bool TrySZSort (Array keys, Array? items, int left, int right) => false;

public int GetUpperBound (int dimension)
{
return GetLowerBound (dimension) + GetLength (dimension) - 1;
Expand Down
5 changes: 0 additions & 5 deletions netcore/System.Private.CoreLib/src/System/String.cs
Expand Up @@ -9,11 +9,6 @@ namespace System
{
partial class String
{
[NonSerialized]
int _stringLength;
[NonSerialized]
char _firstChar;

[Intrinsic]
public static readonly String Empty;

Expand Down

0 comments on commit 4e81814

Please sign in to comment.