Skip to content

Commit 83e3daa

Browse files
authored
Merge pull request #894 from Unity-Technologies/linq-unityaot-profile
Use An AOT-friendly Linq implementation
2 parents d889370 + dab14a9 commit 83e3daa

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../external/corefx/src/System.Linq/src/System/Linq/*.cs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#include winaot_System.Core.dll.sources
2+
../referencesource/System.Core/System/Linq/Enumerable.cs
3+
corefx/SR.cs

mcs/class/referencesource/System.Core/System/Linq/Enumerable.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,11 @@ public string Empty
27762776
{
27772777
get
27782778
{
2779+
#if UNITY_AOT
2780+
return SR.EmptyEnumerable;
2781+
#else
27792782
return Strings.EmptyEnumerable;
2783+
#endif
27802784
}
27812785
}
27822786
}
@@ -2829,4 +2833,49 @@ public object[] Items
28292833
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
28302834
private int count;
28312835
}
2836+
2837+
#if UNITY_AOT
2838+
// <summary>
2839+
/// An iterator that can produce an array or <see cref="List{TElement}"/> through an optimized path.
2840+
/// </summary>
2841+
internal interface IIListProvider<TElement> : IEnumerable<TElement>
2842+
{
2843+
/// <summary>
2844+
/// Produce an array of the sequence through an optimized path.
2845+
/// </summary>
2846+
/// <returns>The array.</returns>
2847+
TElement[] ToArray();
2848+
2849+
/// <summary>
2850+
/// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
2851+
/// </summary>
2852+
/// <returns>The <see cref="List{TElement}"/>.</returns>
2853+
List<TElement> ToList();
2854+
2855+
/// <summary>
2856+
/// Returns the count of elements in the sequence.
2857+
/// </summary>
2858+
/// <param name="onlyIfCheap">If true then the count should only be calculated if doing
2859+
/// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
2860+
/// <returns>The number of elements.</returns>
2861+
int GetCount(bool onlyIfCheap);
2862+
}
2863+
2864+
internal static partial class Error
2865+
{
2866+
internal static Exception ArgumentNull(string s) => new ArgumentNullException(s);
2867+
2868+
internal static Exception ArgumentOutOfRange(string s) => new ArgumentOutOfRangeException(s);
2869+
2870+
internal static Exception MoreThanOneElement() => new InvalidOperationException(SR.MoreThanOneElement);
2871+
2872+
internal static Exception MoreThanOneMatch() => new InvalidOperationException(SR.MoreThanOneMatch);
2873+
2874+
internal static Exception NoElements() => new InvalidOperationException(SR.NoElements);
2875+
2876+
internal static Exception NoMatch() => new InvalidOperationException(SR.NoMatch);
2877+
2878+
internal static Exception NotSupported() => new NotSupportedException();
2879+
}
2880+
#endif
28322881
}

0 commit comments

Comments
 (0)