diff --git a/Src/Compilers/Core/Portable/CodeAnalysis.csproj b/Src/Compilers/Core/Portable/CodeAnalysis.csproj index 6e16ed76da86621a9a9e54af29c7ba215374896f..d3bd221b9551190cdff8bdbf2fbe50e423953f0a 100644 --- a/Src/Compilers/Core/Portable/CodeAnalysis.csproj +++ b/Src/Compilers/Core/Portable/CodeAnalysis.csproj @@ -113,6 +113,7 @@ + @@ -265,7 +266,6 @@ - diff --git a/Src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs b/Src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs index c399c18b3847cc969ff1edfccd5b026aa79084cc..8f88511fead08091777a7f8b16e926dd6e98b2e0 100644 --- a/Src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs +++ b/Src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs @@ -6,16 +6,14 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace Microsoft.CodeAnalysis { /// /// The collection of extension methods for the type /// - public static partial class ImmutableArrayExtensions + internal static class ImmutableArrayExtensions { /// /// Converts a sequence to an immutable array. @@ -213,11 +211,13 @@ public static ImmutableArray WhereAsArray(this ImmutableArray array, Fu { continue; } + Debug.Assert(i > 0); if (builder == null) { builder = ArrayBuilder.GetInstance(); } + builder.Add(a); } else @@ -227,6 +227,7 @@ public static ImmutableArray WhereAsArray(this ImmutableArray array, Fu all = false; continue; } + Debug.Assert(i > 0); if (all) { @@ -258,30 +259,9 @@ public static ImmutableArray WhereAsArray(this ImmutableArray array, Fu } } - /// - /// Adds all elements of the immutable array into the list; The list must not be null. - /// - /// - /// - /// - /// - public static void AddRange(this List list, ImmutableArray items) where U : T - { - Debug.Assert(list != null); - - foreach (var u in items) - { - list.Add(u); - } - } - /// /// Casts the immutable array of a Type to an immutable array of its base type. /// - /// - /// - /// - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ImmutableArray Cast(this ImmutableArray items) where TDerived : class, TBase @@ -311,7 +291,7 @@ public static bool SetEquals(this ImmutableArray array1, ImmutableArray var count1 = array1.Length; var count2 = array2.Length; - //avoid constructing HashSets in these common cases + // avoid constructing HashSets in these common cases if (count1 == 0) { return count2 == 0; @@ -338,9 +318,6 @@ public static bool SetEquals(this ImmutableArray array1, ImmutableArray /// /// Returns an empty array if the input array is null (defaut) /// - /// - /// - /// public static ImmutableArray NullToEmpty(this ImmutableArray array) { return array.IsDefault ? ImmutableArray.Empty : array; @@ -350,10 +327,6 @@ public static ImmutableArray NullToEmpty(this ImmutableArray array) /// 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. /// - /// - /// - /// - /// public static ImmutableArray Distinct(this ImmutableArray array, IEqualityComparer comparer = null) { Debug.Assert(!array.IsDefault); @@ -447,13 +420,18 @@ internal static bool HasDuplicates(this ImmutableArray array, IEqualityCom case 0: case 1: return false; + case 2: return comparer.Equals(array[0], array[1]); + default: var set = new HashSet(comparer); foreach (var i in array) { - if (!set.Add(i)) return true; + if (!set.Add(i)) + { + return true; + } } return false; @@ -475,15 +453,8 @@ public static int Count(this ImmutableArray items, Func predicate ++count; } } - return count; - } - } - internal static class StaticCast - { - internal static ImmutableArray From(ImmutableArray from) where TDerived : class, T - { - return ImmutableArray.Create(from); + return count; } } } diff --git a/Src/Compilers/Core/Portable/Collections/StaticCast.cs b/Src/Compilers/Core/Portable/Collections/StaticCast.cs new file mode 100644 index 0000000000000000000000000000000000000000..3191bfadefbb38c93c7b70c2be549a8f56d4aee8 --- /dev/null +++ b/Src/Compilers/Core/Portable/Collections/StaticCast.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Immutable; + +namespace Microsoft.CodeAnalysis +{ + internal static class StaticCast + { + internal static ImmutableArray From(ImmutableArray from) where TDerived : class, T + { + return ImmutableArray.Create(from); + } + } +} diff --git a/Src/Compilers/Core/Portable/InternalUtilities/ObjectPool`1.cs b/Src/Compilers/Core/SharedCollections/ObjectPool`1.cs similarity index 100% rename from Src/Compilers/Core/Portable/InternalUtilities/ObjectPool`1.cs rename to Src/Compilers/Core/SharedCollections/ObjectPool`1.cs diff --git a/Src/Compilers/Core/SharedCollections/SharedCollections.projitems b/Src/Compilers/Core/SharedCollections/SharedCollections.projitems index 681878550047e24fe19935994e74af4b4abb0578..4939d9a867e6f78def3ad137018d02854f1e4440 100644 --- a/Src/Compilers/Core/SharedCollections/SharedCollections.projitems +++ b/Src/Compilers/Core/SharedCollections/SharedCollections.projitems @@ -15,6 +15,7 @@ true + true diff --git a/Src/Test/PdbUtilities/PdbUtilities.csproj b/Src/Test/PdbUtilities/PdbUtilities.csproj index 0214629e69d0488775717322bd94a97271545d48..d79f5896f89267c2d792da28c5ea9cf20adbc282 100644 --- a/Src/Test/PdbUtilities/PdbUtilities.csproj +++ b/Src/Test/PdbUtilities/PdbUtilities.csproj @@ -26,9 +26,6 @@ InternalUtilities\ComStreamWrapper.cs - - InternalUtilities\ObjectPool`1.cs - diff --git a/Src/Workspaces/Core/Desktop/Workspace/Host/Mef/DesktopMefHostServices.cs b/Src/Workspaces/Core/Desktop/Workspace/Host/Mef/DesktopMefHostServices.cs index 223dbee2eee391ea4b48199f67179e66d7cd6c52..e2fc15ed3f1d138fc0c4933fec1936fbcf910628 100644 --- a/Src/Workspaces/Core/Desktop/Workspace/Host/Mef/DesktopMefHostServices.cs +++ b/Src/Workspaces/Core/Desktop/Workspace/Host/Mef/DesktopMefHostServices.cs @@ -47,7 +47,7 @@ private static ImmutableArray CreateDefaultAssemblies() "Microsoft.CodeAnalysis.VisualBasic.Workspaces.Desktop", }; - return MefHostServices.DefaultAssemblies.Concat(MefHostServices.LoadNearbyAssemblies(assemblyNames)).ToImmutableArray(); + return MefHostServices.DefaultAssemblies.Concat(MefHostServices.LoadNearbyAssemblies(assemblyNames)); } } } \ No newline at end of file diff --git a/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs b/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs index dfec478951fecc924a9d99a13f7f51e3a0a473d8..753e0bb6c0f07d9a1c2b0e28158524cee93cb6a5 100644 --- a/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs +++ b/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs @@ -55,7 +55,7 @@ public override ImmutableArray TypeArguments { get { - return this.typeArguments.AsImmutable(); + return ImmutableArray.CreateRange(this.typeArguments); } } diff --git a/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedNamedTypeSymbol.cs b/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedNamedTypeSymbol.cs index 86eb3c381ee324ea99af960887ae62ca923dd10e..94355aa1dfe9ebde105509b4593dc95aa4af58aa 100644 --- a/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedNamedTypeSymbol.cs +++ b/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedNamedTypeSymbol.cs @@ -30,7 +30,7 @@ public override ImmutableArray TypeArguments { get { - return this.typeArguments.AsImmutable(); + return ImmutableArray.CreateRange(this.typeArguments); } } @@ -143,7 +143,7 @@ public override ImmutableArray Constructors public override ImmutableArray GetTypeMembers() { // TODO(cyrusn): construct these. - return this.constructedFrom.TypeMembers.Cast().AsImmutable(); + return ImmutableArray.CreateRange(this.constructedFrom.TypeMembers.Cast()); } public override TypeKind TypeKind diff --git a/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationNamedTypeSymbol.cs b/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationNamedTypeSymbol.cs index 6c3a90b3993e2ada7e592fd20a05aad97e08133c..caee35efd49dcfadef1dd383d0477f435341ae1c 100644 --- a/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationNamedTypeSymbol.cs +++ b/Src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationNamedTypeSymbol.cs @@ -168,7 +168,7 @@ public override ImmutableArray TypeParameters { get { - return this.typeParameters.AsImmutable(); + return ImmutableArray.CreateRange(this.typeParameters); } } @@ -184,18 +184,18 @@ public override ImmutableArray Interfaces { get { - return this.interfaces.AsImmutable(); + return ImmutableArray.CreateRange(this.interfaces); } } public override ImmutableArray GetMembers() { - return this.members.Concat(this.TypeMembers).AsImmutable(); + return ImmutableArray.CreateRange(this.members.Concat(this.TypeMembers)); } public override ImmutableArray GetTypeMembers() { - return this.TypeMembers.Cast().AsImmutable(); + return ImmutableArray.CreateRange(this.TypeMembers.Cast()); } public override ImmutableArray InstanceConstructors @@ -203,9 +203,8 @@ public override ImmutableArray InstanceConstructors get { // NOTE(cyrusn): remember to Construct the result if we implement this. - return this.GetMembers().OfType() - .Where(m => m.MethodKind == MethodKind.Constructor && !m.IsStatic) - .AsImmutable(); + return ImmutableArray.CreateRange( + this.GetMembers().OfType().Where(m => m.MethodKind == MethodKind.Constructor && !m.IsStatic)); } } @@ -214,9 +213,8 @@ public override ImmutableArray StaticConstructors get { // NOTE(cyrusn): remember to Construct the result if we implement this. - return this.GetMembers().OfType() - .Where(m => m.MethodKind == MethodKind.StaticConstructor && m.IsStatic) - .AsImmutable(); + return ImmutableArray.CreateRange( + this.GetMembers().OfType().Where(m => m.MethodKind == MethodKind.StaticConstructor && m.IsStatic)); } } diff --git a/Src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs b/Src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs index c6c038bd74d12b4ec53af344395db5c8eb1b6041..d4469a865730dd51ee4cc81ea1916acdc66c43cf 100644 --- a/Src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs +++ b/Src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Threading; using Microsoft.CodeAnalysis; @@ -136,8 +137,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList t.SubstituteTypes(mapping, typeGenerator)).AsImmutable(); + newTypeParameter.ConstraintTypes = ImmutableArray.CreateRange(newTypeParameter.ConstraintTypes, t => t.SubstituteTypes(mapping, typeGenerator)); } return newTypeParameters.Cast().ToList(); diff --git a/Src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs b/Src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs index f49d71246f5dac65fd462d7bb14d297e5bccb91b..6b18789bf2150cae76ca4134399194efdf900972 100644 --- a/Src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs +++ b/Src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs @@ -427,7 +427,7 @@ public static ImmutableArray GetAllTypeArguments(this ISymbol symbo containingType = containingType.ContainingType; } - return results.AsImmutable(); + return ImmutableArray.CreateRange(results); } public static bool IsAttribute(this ISymbol symbol) diff --git a/Src/Workspaces/Core/Portable/Workspaces.csproj b/Src/Workspaces/Core/Portable/Workspaces.csproj index b7ecb91de67327cd3965e809b543f7d6ea1396ff..520974dd6f655dd4ad66c52bdd1dc2ab370a33c3 100644 --- a/Src/Workspaces/Core/Portable/Workspaces.csproj +++ b/Src/Workspaces/Core/Portable/Workspaces.csproj @@ -49,6 +49,9 @@ + + InternalUtilities\ImmutableArrayExtensions.cs + MetadataReference\MetadataFileReferenceProvider.cs @@ -188,9 +191,6 @@ InternalUtilities\WeakReferenceExtensions.cs - - InternalUtilities\ObjectPool`1.cs - Serialization\FixedObjectBinder.cs @@ -953,6 +953,7 @@ Designer +