diff --git a/src/Compilers/CSharp/Portable/Symbols/Extensions/SourceExtensionImplementationMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Extensions/SourceExtensionImplementationMethodSymbol.cs index e4d8d0ea5c543..c0bf0e345af36 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Extensions/SourceExtensionImplementationMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Extensions/SourceExtensionImplementationMethodSymbol.cs @@ -5,6 +5,7 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Globalization; +using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using Microsoft.CodeAnalysis.CSharp.Emit; diff --git a/src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs b/src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs index 7303c2d73f428..b037b876d4502 100644 --- a/src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs +++ b/src/Dependencies/Collections/Extensions/ImmutableArrayExtensions.cs @@ -1031,99 +1031,6 @@ public static bool IsSubsetOf(this ImmutableArray array, Imm set.Free(); return true; } - - #region Binary Compat - - // These helpers should be in System.Linq namespace below. However, they are currently - // used by partners with IVT access to Roslyn, so they have to stay here for now. - - /// - /// Specialization of for . - /// - public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second) - => first.AddRange(second); - - /// - /// Variant of . - /// - public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third) - { - var builder = new T[first.Length + second.Length + third.Length]; - - var index = 0; - first.CopyTo(builder, index); - index += first.Length; - second.CopyTo(builder, index); - index += second.Length; - third.CopyTo(builder, index); - - return ImmutableCollectionsMarshal.AsImmutableArray(builder); - } - - /// - /// Variant of . - /// - public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third, ImmutableArray fourth) - { - var builder = new T[first.Length + second.Length + third.Length + fourth.Length]; - - var index = 0; - first.CopyTo(builder, index); - index += first.Length; - second.CopyTo(builder, index); - index += second.Length; - third.CopyTo(builder, index); - index += third.Length; - fourth.CopyTo(builder, index); - - return ImmutableCollectionsMarshal.AsImmutableArray(builder); - } - - /// - /// Variant of . - /// - public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third, ImmutableArray fourth, ImmutableArray fifth) - { - var builder = new T[first.Length + second.Length + third.Length + fourth.Length + fifth.Length]; - - var index = 0; - first.CopyTo(builder, index); - index += first.Length; - second.CopyTo(builder, index); - index += second.Length; - third.CopyTo(builder, index); - index += third.Length; - fourth.CopyTo(builder, index); - index += fourth.Length; - fifth.CopyTo(builder, index); - - return ImmutableCollectionsMarshal.AsImmutableArray(builder); - } - - /// - /// Variant of . - /// - public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third, ImmutableArray fourth, ImmutableArray fifth, ImmutableArray sixth) - { - var builder = new T[first.Length + second.Length + third.Length + fourth.Length + fifth.Length + sixth.Length]; - - var index = 0; - first.CopyTo(builder, index); - index += first.Length; - second.CopyTo(builder, index); - index += second.Length; - third.CopyTo(builder, index); - index += third.Length; - fourth.CopyTo(builder, index); - index += fourth.Length; - fifth.CopyTo(builder, index); - index += fifth.Length; - sixth.CopyTo(builder, index); - - return ImmutableCollectionsMarshal.AsImmutableArray(builder); - } - - #endregion } } @@ -1262,12 +1169,152 @@ public static int Sum(this ImmutableArray items, Func selecto return sum; } + /// + /// Specialization of for . + /// + public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second) + => first.AddRange(second); + /// /// Variant of . /// public static ImmutableArray Concat(this ImmutableArray first, T second) => first.Add(second); + /// + /// Variant of . + /// + public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third) + { + var builder = new T[first.Length + second.Length + third.Length]; + var index = 0; + + foreach (var item in first) + { + builder[index++] = item; + } + + foreach (var item in second) + { + builder[index++] = item; + } + + foreach (var item in third) + { + builder[index++] = item; + } + + return ImmutableCollectionsMarshal.AsImmutableArray(builder); + } + + /// + /// Variant of . + /// + public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third, ImmutableArray fourth) + { + var builder = new T[first.Length + second.Length + third.Length + fourth.Length]; + var index = 0; + + foreach (var item in first) + { + builder[index++] = item; + } + + foreach (var item in second) + { + builder[index++] = item; + } + + foreach (var item in third) + { + builder[index++] = item; + } + + foreach (var item in fourth) + { + builder[index++] = item; + } + + return ImmutableCollectionsMarshal.AsImmutableArray(builder); + } + + /// + /// Variant of . + /// + public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third, ImmutableArray fourth, ImmutableArray fifth) + { + var builder = new T[first.Length + second.Length + third.Length + fourth.Length + fifth.Length]; + var index = 0; + + foreach (var item in first) + { + builder[index++] = item; + } + + foreach (var item in second) + { + builder[index++] = item; + } + + foreach (var item in third) + { + builder[index++] = item; + } + + foreach (var item in fourth) + { + builder[index++] = item; + } + + foreach (var item in fifth) + { + builder[index++] = item; + } + + return ImmutableCollectionsMarshal.AsImmutableArray(builder); + } + + /// + /// Variant of . + /// + public static ImmutableArray Concat(this ImmutableArray first, ImmutableArray second, ImmutableArray third, ImmutableArray fourth, ImmutableArray fifth, ImmutableArray sixth) + { + var builder = new T[first.Length + second.Length + third.Length + fourth.Length + fifth.Length + sixth.Length]; + var index = 0; + + foreach (var item in first) + { + builder[index++] = item; + } + + foreach (var item in second) + { + builder[index++] = item; + } + + foreach (var item in third) + { + builder[index++] = item; + } + + foreach (var item in fourth) + { + builder[index++] = item; + } + + foreach (var item in fifth) + { + builder[index++] = item; + } + + foreach (var item in sixth) + { + builder[index++] = item; + } + + return ImmutableCollectionsMarshal.AsImmutableArray(builder); + } + /// /// Returns an array of distinct elements, preserving the order in the original array. /// If the array has no duplicates, the original array is returned. The original array must not be null.