提交 d6e99da9 编写于 作者: V VSadov

PERF: Avoiding some unnecessary allocations/boxing in metadata emit

 (changeset 1211723)
上级 1b5b107c
......@@ -226,7 +226,7 @@ protected virtual bool IsAttributeConditionallyOmitted(NamedTypeSymbol attribute
if (attributeType.IsConditional)
{
IEnumerable<string> conditionalSymbols = attributeType.GetAppliedConditionalSymbols();
ImmutableArray<string> conditionalSymbols = attributeType.GetAppliedConditionalSymbols();
Debug.Assert(conditionalSymbols != null);
if (syntaxTree.IsAnyPreprocessorSymbolDefined(conditionalSymbols))
{
......
......@@ -334,7 +334,7 @@ internal static bool HasReferenceDirectives(this SyntaxTree tree)
return csharpTree != null && csharpTree.HasReferenceDirectives;
}
internal static bool IsAnyPreprocessorSymbolDefined(this SyntaxTree tree, IEnumerable<string> conditionalSymbols)
internal static bool IsAnyPreprocessorSymbolDefined(this SyntaxTree tree, ImmutableArray<string> conditionalSymbols)
{
var csharpTree = tree as CSharpSyntaxTree;
return csharpTree != null && csharpTree.IsAnyPreprocessorSymbolDefined(conditionalSymbols);
......
......@@ -15,14 +15,21 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal abstract partial class CSharpAttributeData : Cci.ICustomAttribute
{
IEnumerable<Cci.IMetadataExpression> Cci.ICustomAttribute.GetArguments(Microsoft.CodeAnalysis.Emit.Context context)
ImmutableArray<Cci.IMetadataExpression> Cci.ICustomAttribute.GetArguments(Microsoft.CodeAnalysis.Emit.Context context)
{
foreach (var argument in this.CommonConstructorArguments)
var commonArgs = this.CommonConstructorArguments;
if(commonArgs.IsEmpty)
{
Debug.Assert(argument.Kind != TypedConstantKind.Error);
return ImmutableArray<Cci.IMetadataExpression>.Empty;
}
yield return CreateMetadataExpression(argument, context);
var builder = ArrayBuilder<Cci.IMetadataExpression>.GetInstance();
foreach (var argument in commonArgs)
{
Debug.Assert(argument.Kind != TypedConstantKind.Error);
builder.Add(CreateMetadataExpression(argument, context));
}
return builder.ToImmutableAndFree();
}
Cci.IMethodReference Cci.ICustomAttribute.Constructor(Microsoft.CodeAnalysis.Emit.Context context)
......@@ -31,12 +38,20 @@ Cci.IMethodReference Cci.ICustomAttribute.Constructor(Microsoft.CodeAnalysis.Emi
return (Cci.IMethodReference)moduleBeingBuilt.Translate(this.AttributeConstructor, (CSharpSyntaxNode)context.SyntaxNodeOpt, context.Diagnostics);
}
IEnumerable<Cci.IMetadataNamedArgument> Cci.ICustomAttribute.GetNamedArguments(Microsoft.CodeAnalysis.Emit.Context context)
ImmutableArray<Cci.IMetadataNamedArgument> Cci.ICustomAttribute.GetNamedArguments(Microsoft.CodeAnalysis.Emit.Context context)
{
foreach (var namedArgument in this.CommonNamedArguments)
var commonArgs = this.CommonNamedArguments;
if (commonArgs.IsEmpty)
{
return ImmutableArray<Cci.IMetadataNamedArgument>.Empty;
}
var builder = ArrayBuilder<Cci.IMetadataNamedArgument>.GetInstance();
foreach (var namedArgument in commonArgs)
{
yield return CreateMetadataNamedArgument(namedArgument.Key, namedArgument.Value, context);
builder.Add(CreateMetadataNamedArgument(namedArgument.Key, namedArgument.Value, context));
}
return builder.ToImmutableAndFree();
}
int Cci.ICustomAttribute.ArgumentCount
......
......@@ -51,7 +51,7 @@ Cci.IMethodDefinition Cci.IMethodReference.GetResolvedMethod(Microsoft.CodeAnaly
return underlyingMethod.GetResolvedMethod(context);
}
IEnumerable<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
ImmutableArray<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
{
get
{
......@@ -97,7 +97,7 @@ ushort Cci.ISignature.ParameterCount
get { return underlyingMethod.ParameterCount; }
}
IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
{
return underlyingMethod.GetParameters(context);
}
......
......@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using System.Diagnostics;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.CSharp.Emit
{
......@@ -65,11 +66,11 @@ Microsoft.Cci.IMethodDefinition Microsoft.Cci.IMethodReference.GetResolvedMethod
return null;
}
IEnumerable<Microsoft.Cci.IParameterTypeInformation> Microsoft.Cci.IMethodReference.ExtraParameters
ImmutableArray<Microsoft.Cci.IParameterTypeInformation> Microsoft.Cci.IMethodReference.ExtraParameters
{
get
{
return SpecializedCollections.EmptyEnumerable<Microsoft.Cci.IParameterTypeInformation>();
return ImmutableArray<Microsoft.Cci.IParameterTypeInformation>.Empty;
}
}
......@@ -81,7 +82,7 @@ Microsoft.Cci.CallingConvention Microsoft.Cci.ISignature.CallingConvention
}
}
IEnumerable<Microsoft.Cci.IParameterTypeInformation> Microsoft.Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
ImmutableArray<Microsoft.Cci.IParameterTypeInformation> Microsoft.Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
{
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
return moduleBeingBuilt.Translate(UnderlyingMethod.Parameters);
......
......@@ -171,11 +171,11 @@ private Cci.IMethodDefinition ResolvedMethodImpl(Microsoft.CodeAnalysis.Emit.Con
return null;
}
IEnumerable<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
ImmutableArray<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
{
get
{
return SpecializedCollections.EmptyEnumerable<Cci.IParameterTypeInformation>();
return ImmutableArray<Cci.IParameterTypeInformation>.Empty;
}
}
......@@ -187,14 +187,14 @@ Cci.CallingConvention Cci.ISignature.CallingConvention
}
}
IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
{
Debug.Assert(this.IsDefinitionOrDistinct());
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
if (this.IsDefinition && this.ContainingModule == moduleBeingBuilt.SourceModule)
{
return EnumerateDefinitionParameters();
return StaticCast<Cci.IParameterTypeInformation>.From(this.EnumerateDefinitionParameters());
}
else
{
......@@ -202,19 +202,11 @@ IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsof
}
}
private IEnumerable<Cci.IParameterDefinition> EnumerateDefinitionParameters()
private ImmutableArray<Cci.IParameterDefinition> EnumerateDefinitionParameters()
{
Debug.Assert(this.Parameters.All(p => p.IsDefinition));
var parameters = this.Parameters;
if (parameters.Length != 0)
{
return this.Parameters;
}
else
{
return SpecializedCollections.EmptyEnumerable<Cci.IParameterDefinition>();
}
return StaticCast<Cci.IParameterDefinition>.From(this.Parameters);
}
IEnumerable<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
......@@ -570,7 +562,7 @@ bool Cci.IMethodDefinition.IsVirtual
/// </summary>
internal abstract bool IsMetadataFinal();
IEnumerable<Cci.IParameterDefinition> Cci.IMethodDefinition.Parameters
ImmutableArray<Cci.IParameterDefinition> Cci.IMethodDefinition.Parameters
{
get
{
......
......@@ -1148,22 +1148,16 @@ public static Cci.TypeMemberVisibility MemberVisibility(Symbol symbol)
return methodRef;
}
internal IEnumerable<Cci.IParameterTypeInformation> Translate(ImmutableArray<ParameterSymbol> @params)
internal ImmutableArray<Cci.IParameterTypeInformation> Translate(ImmutableArray<ParameterSymbol> @params)
{
Debug.Assert(@params.All(p => p.IsDefinitionOrDistinct()));
if (@params.Length == 0)
{
return SpecializedCollections.EmptyEnumerable<Cci.IParameterTypeInformation>();
}
var firstParam = @params.First();
bool mustBeTranslated = MustBeWrapped(firstParam);
bool mustBeTranslated = @params.Any() && MustBeWrapped(@params.First());
Debug.Assert(@params.All(p => mustBeTranslated == MustBeWrapped(p)), "either all or no parameters need translating");
if (!mustBeTranslated)
{
return @params;
return StaticCast<Cci.IParameterTypeInformation>.From(@params);
}
return TranslateAll(@params);
......@@ -1189,12 +1183,9 @@ private static bool MustBeWrapped(ParameterSymbol param)
return false;
}
private IEnumerable<Cci.IParameterTypeInformation> TranslateAll(ImmutableArray<ParameterSymbol> @params)
private ImmutableArray<Cci.IParameterTypeInformation> TranslateAll(ImmutableArray<ParameterSymbol> @params)
{
foreach (var param in @params)
{
yield return CreateParameterTypeInformationWrapper(param);
}
return @params.SelectAsArray(param => CreateParameterTypeInformationWrapper(param));
}
private Cci.IParameterTypeInformation CreateParameterTypeInformationWrapper(ParameterSymbol param)
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Cci = Microsoft.Cci;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
......@@ -106,12 +107,12 @@ bool Cci.IPropertyDefinition.IsSpecialName
}
}
IEnumerable<Cci.IParameterDefinition> Cci.IPropertyDefinition.Parameters
ImmutableArray<Cci.IParameterDefinition> Cci.IPropertyDefinition.Parameters
{
get
{
CheckDefinitionInvariant();
return this.Parameters;
return StaticCast<Cci.IParameterDefinition>.From(this.Parameters);
}
}
......@@ -152,10 +153,10 @@ ushort Cci.ISignature.ParameterCount
}
}
IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
{
CheckDefinitionInvariant();
return this.Parameters;
return StaticCast<Cci.IParameterTypeInformation>.From(this.Parameters);
}
IEnumerable<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
......
......@@ -448,8 +448,8 @@ protected virtual ImmutableArray<PendingBranch> RemoveReturns()
// track exception states.
result = this.pendingBranches
.Where(b => b.Branch != null)
.ToArray()
.AsImmutableOrNull();
var oldExceptions = this.pendingBranches[0];
Debug.Assert(oldExceptions.Branch == null);
this.pendingBranches.Clear();
......
......@@ -311,9 +311,9 @@ internal override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInform
throw ExceptionUtilities.Unreachable;
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
internal override AttributeUsageInfo GetAttributeUsageInfo()
......
......@@ -423,9 +423,9 @@ internal override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInform
throw ExceptionUtilities.Unreachable;
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
internal override AttributeUsageInfo GetAttributeUsageInfo()
......
......@@ -484,9 +484,9 @@ internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurit
throw ExceptionUtilities.Unreachable;
}
internal sealed override IEnumerable<string> GetAppliedConditionalSymbols()
internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
internal override AttributeUsageInfo GetAttributeUsageInfo()
......
......@@ -1896,12 +1896,12 @@ private NamedTypeSymbol MakeComImportCoClassType()
return null;
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
var uncommon = GetUncommonProperties();
if (uncommon == noUncommonProperties)
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
if (uncommon.lazyConditionalAttributeSymbols.IsDefault)
......
......@@ -382,7 +382,7 @@ private bool CallsAreConditionallyOmitted(SyntaxTree syntaxTree)
{
if (this.IsConditional)
{
IEnumerable<string> conditionalSymbols = this.GetAppliedConditionalSymbols();
ImmutableArray<string> conditionalSymbols = this.GetAppliedConditionalSymbols();
Debug.Assert(conditionalSymbols != null);
if (syntaxTree.IsAnyPreprocessorSymbolDefined(conditionalSymbols))
{
......
......@@ -1066,7 +1066,7 @@ protected CharSet DefaultMarshallingCharSet
/// <summary>
/// Returns a sequence of preprocessor symbols specified in <see cref="T:ConditionalAttribute"/> applied on this symbol, or null if there are none.
/// </summary>
internal abstract IEnumerable<string> GetAppliedConditionalSymbols();
internal abstract ImmutableArray<string> GetAppliedConditionalSymbols();
/// <summary>
/// If CoClassAttribute was applied to the type and the attribute argument is a valid named type argument, i.e. accessible class type, then it returns the type symbol for the argument.
......
......@@ -552,7 +552,7 @@ internal override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInform
return this.underlyingType.GetSecurityInformation();
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return this.underlyingType.GetAppliedConditionalSymbols();
}
......
......@@ -145,9 +145,9 @@ internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurit
throw ExceptionUtilities.Unreachable;
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
internal override ObsoleteAttributeData ObsoleteAttributeData
......
......@@ -883,10 +883,10 @@ internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurit
return null;
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
var data = GetEarlyDecodedWellKnownAttributeData();
return data != null ? data.ConditionalSymbols : SpecializedCollections.EmptyEnumerable<string>();
return data != null ? data.ConditionalSymbols : ImmutableArray<string>.Empty;
}
internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttributeData> boundAttributes, ImmutableArray<AttributeSyntax> allAttributeSyntaxNodes, DiagnosticBag diagnostics, AttributeLocation symbolPart, WellKnownAttributeData decodedData)
......
......@@ -469,7 +469,7 @@ internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurit
return originalDefinition.GetSecurityInformation();
}
internal sealed override IEnumerable<string> GetAppliedConditionalSymbols()
internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return originalDefinition.GetAppliedConditionalSymbols();
}
......
......@@ -272,9 +272,9 @@ internal sealed override ObsoleteAttributeData ObsoleteAttributeData
get { return null; }
}
internal sealed override IEnumerable<string> GetAppliedConditionalSymbols()
internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
internal override bool HasDeclarativeSecurity
......
......@@ -153,7 +153,7 @@ private Syntax.InternalSyntax.DirectiveStack GetDirectives()
return this.directives;
}
internal bool IsAnyPreprocessorSymbolDefined(IEnumerable<string> conditionalSymbols)
internal bool IsAnyPreprocessorSymbolDefined(ImmutableArray<string> conditionalSymbols)
{
System.Diagnostics.Debug.Assert(conditionalSymbols != null);
......
......@@ -286,9 +286,9 @@ internal override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInform
return null;
}
internal override IEnumerable<string> GetAppliedConditionalSymbols()
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
{
return SpecializedCollections.EmptyEnumerable<string>();
return ImmutableArray<string>.Empty;
}
internal override AttributeUsageInfo GetAttributeUsageInfo()
......
......@@ -5,6 +5,7 @@
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Cci = Microsoft.Cci;
using System.Collections.Immutable;
// Contains support for pseudo-methods on multidimensional arrays.
......@@ -221,20 +222,19 @@ public override Cci.ITypeReference GetType(Microsoft.CodeAnalysis.Emit.Context c
return context.Module.GetPlatformType(Cci.PlatformType.SystemVoid, context);
}
protected override ArrayMethodParameterInfo[] MakeParameters()
protected override ImmutableArray<ArrayMethodParameterInfo> MakeParameters()
{
var indexNum = (ushort)arrayType.Rank;
var parameters = new ArrayMethodParameterInfo[indexNum + 1];
int rank = (int)arrayType.Rank;
var parameters = ArrayBuilder<ArrayMethodParameterInfo>.GetInstance(rank + 1);
for (ushort i = 0; i < indexNum; i++)
for (int i = 0; i < rank; i++)
{
parameters[i] = ArrayMethodParameterInfo.GetIndexParameter(i);
parameters.Add(ArrayMethodParameterInfo.GetIndexParameter((ushort)i));
}
parameters[indexNum] = new ArraySetValueParameterInfo(indexNum, arrayType);
return parameters;
}
parameters.Add(new ArraySetValueParameterInfo((ushort)rank, arrayType));
return parameters.ToImmutableAndFree();
}
}
}
......@@ -333,7 +333,7 @@ public override Cci.ITypeReference GetType(Microsoft.CodeAnalysis.Emit.Context c
/// </summary>
internal abstract class ArrayMethod : Cci.IMethodReference
{
private readonly ArrayMethodParameterInfo[] parameters;
private readonly ImmutableArray<ArrayMethodParameterInfo> parameters;
protected readonly Cci.IArrayTypeReference arrayType;
protected ArrayMethod(Cci.IArrayTypeReference arrayType)
......@@ -352,21 +352,22 @@ public virtual bool ReturnValueIsByRef
}
// Set overrides this to include "value" parameter.
protected virtual ArrayMethodParameterInfo[] MakeParameters()
protected virtual ImmutableArray<ArrayMethodParameterInfo> MakeParameters()
{
var parameters = new ArrayMethodParameterInfo[arrayType.Rank];
int rank = (int)arrayType.Rank;
var parameters = ArrayBuilder<ArrayMethodParameterInfo>.GetInstance(rank);
for (ushort i = 0; i < parameters.Length; i++)
for (int i = 0; i < rank; i++)
{
parameters[i] = ArrayMethodParameterInfo.GetIndexParameter(i);
parameters.Add(ArrayMethodParameterInfo.GetIndexParameter((ushort)i));
}
return parameters;
return parameters.ToImmutableAndFree();
}
public IEnumerable<Cci.IParameterTypeInformation> GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
public ImmutableArray<Cci.IParameterTypeInformation> GetParameters(Microsoft.CodeAnalysis.Emit.Context context)
{
return parameters;
return StaticCast<Cci.IParameterTypeInformation>.From(parameters);
}
public bool AcceptsExtraArguments
......@@ -389,9 +390,9 @@ public Cci.IMethodDefinition GetResolvedMethod(Microsoft.CodeAnalysis.Emit.Conte
return null;
}
public IEnumerable<Cci.IParameterTypeInformation> ExtraParameters
public ImmutableArray<Cci.IParameterTypeInformation> ExtraParameters
{
get { return SpecializedCollections.EmptyEnumerable<Cci.IParameterTypeInformation>(); }
get { return ImmutableArray<Cci.IParameterTypeInformation>.Empty; }
}
public Cci.IGenericMethodInstanceReference AsGenericMethodInstanceReference
......
......@@ -68,7 +68,7 @@ void Cci.IMethodBody.Dispatch(Cci.MetadataVisitor visitor)
throw ExceptionUtilities.Unreachable;
}
IEnumerable<Cci.ExceptionHandlerRegion> Cci.IMethodBody.ExceptionRegions
ImmutableArray<Cci.ExceptionHandlerRegion> Cci.IMethodBody.ExceptionRegions
{
get { return this.exceptionHandlers; }
}
......@@ -78,9 +78,9 @@ bool Cci.IMethodBody.LocalsAreZeroed
get { return true; }
}
IEnumerable<Cci.ILocalDefinition> Cci.IMethodBody.LocalVariables
ImmutableArray<Cci.ILocalDefinition> Cci.IMethodBody.LocalVariables
{
get { return this.locals; }
get { return StaticCast<Cci.ILocalDefinition>.From(this.locals); }
}
Cci.IMethodDefinition Cci.IMethodBody.MethodDefinition
......
......@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Cci = Microsoft.Cci;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.CodeGen
{
......@@ -44,7 +45,7 @@ public PermissionSetAttributeWithFileReference(Cci.ICustomAttribute sourceAttrib
/// <summary>
/// Zero or more positional arguments for the attribute constructor.
/// </summary>
public IEnumerable<Cci.IMetadataExpression> GetArguments(Microsoft.CodeAnalysis.Emit.Context context)
public ImmutableArray<Cci.IMetadataExpression> GetArguments(Microsoft.CodeAnalysis.Emit.Context context)
{
return this.sourceAttribute.GetArguments(context);
}
......@@ -60,7 +61,7 @@ public Cci.IMethodReference Constructor(Microsoft.CodeAnalysis.Emit.Context cont
/// <summary>
/// Zero or more named arguments that specify values for fields and properties of the attribute.
/// </summary>
public IEnumerable<Cci.IMetadataNamedArgument> GetNamedArguments(Microsoft.CodeAnalysis.Emit.Context context)
public ImmutableArray<Cci.IMetadataNamedArgument> GetNamedArguments(Microsoft.CodeAnalysis.Emit.Context context)
{
// Perform fixup
Cci.ITypeReference stringType = context.Module.GetPlatformType(Cci.PlatformType.SystemString, context);
......@@ -108,7 +109,7 @@ public IEnumerable<Cci.IMetadataNamedArgument> GetNamedArguments(Microsoft.CodeA
}
// Synthesize a named attribute argument "Hex = hexFileContent".
yield return new HexPropertyMetadataNamedArgument(stringType, new MetadataConstant(stringType, hexFileContent));
return ImmutableArray.Create<Cci.IMetadataNamedArgument>(new HexPropertyMetadataNamedArgument(stringType, new MetadataConstant(stringType, hexFileContent)));
}
// internal for testing purposes.
......
......@@ -7,6 +7,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.CodeGen
{
......@@ -143,7 +144,7 @@ private static void VisitMethodReference(Microsoft.Cci.IMethodReference methodRe
}
}
private static void VisitParameters(IEnumerable<Microsoft.Cci.IParameterTypeInformation> parameters, Microsoft.CodeAnalysis.Emit.Context context)
private static void VisitParameters(ImmutableArray<Microsoft.Cci.IParameterTypeInformation> parameters, Microsoft.CodeAnalysis.Emit.Context context)
{
foreach (var param in parameters)
{
......
......@@ -135,9 +135,9 @@ public static ImmutableArray<byte> ToImmutable(this MemoryStream stream)
}
var builder = ArrayBuilder<TResult>.GetInstance(items.Length);
foreach (var e in items)
for (int i = 0; i < items.Length; i++)
{
builder.Add(map(e));
builder.Add(map(items[i]));
}
return builder.ToImmutableAndFree();
......
......@@ -120,9 +120,9 @@ void Cci.IMethodBody.Dispatch(Cci.MetadataVisitor visitor)
visitor.Visit((Cci.IMethodBody)this);
}
IEnumerable<Cci.ExceptionHandlerRegion> Cci.IMethodBody.ExceptionRegions
ImmutableArray<Cci.ExceptionHandlerRegion> Cci.IMethodBody.ExceptionRegions
{
get { return SpecializedCollections.EmptyEnumerable<Cci.ExceptionHandlerRegion>(); }
get { return ImmutableArray<Cci.ExceptionHandlerRegion>.Empty; }
}
bool Cci.IMethodBody.LocalsAreZeroed
......@@ -130,9 +130,9 @@ bool Cci.IMethodBody.LocalsAreZeroed
get { return false; }
}
IEnumerable<Cci.ILocalDefinition> Cci.IMethodBody.LocalVariables
ImmutableArray<Cci.ILocalDefinition> Cci.IMethodBody.LocalVariables
{
get { return SpecializedCollections.EmptyEnumerable<Cci.ILocalDefinition>(); }
get { return ImmutableArray<Cci.ILocalDefinition>.Empty; }
}
Cci.IMethodDefinition Cci.IMethodBody.MethodDefinition
......@@ -331,11 +331,11 @@ System.Reflection.MethodImplAttributes Cci.IMethodDefinition.GetImplementationAt
return GetImplementationAttributes(context);
}
IEnumerable<Cci.IParameterDefinition> Cci.IMethodDefinition.Parameters
ImmutableArray<Cci.IParameterDefinition> Cci.IMethodDefinition.Parameters
{
get
{
return parameters;
return StaticCast<Cci.IParameterDefinition>.From(parameters);
}
}
......@@ -453,12 +453,12 @@ Cci.IMethodDefinition Cci.IMethodReference.GetResolvedMethod(Context context)
return this;
}
IEnumerable<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
ImmutableArray<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
{
get
{
// This is a definition, no information about extra parameters
return SpecializedCollections.EmptyEnumerable<Cci.IParameterTypeInformation>();
return ImmutableArray<Cci.IParameterTypeInformation>.Empty;
}
}
......@@ -494,9 +494,9 @@ ushort Cci.ISignature.ParameterCount
}
}
IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Context context)
ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Context context)
{
return parameters;
return StaticCast<Cci.IParameterTypeInformation>.From(parameters);
}
IEnumerable<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
......
......@@ -122,9 +122,9 @@ bool Cci.IPropertyDefinition.IsSpecialName
}
}
IEnumerable<Cci.IParameterDefinition> Cci.IPropertyDefinition.Parameters
ImmutableArray<Cci.IParameterDefinition> Cci.IPropertyDefinition.Parameters
{
get { return parameters; }
get { return StaticCast<Cci.IParameterDefinition>.From(parameters); }
}
Cci.CallingConvention Cci.ISignature.CallingConvention
......@@ -140,9 +140,9 @@ ushort Cci.ISignature.ParameterCount
get { return (ushort)parameters.Length; }
}
IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Context context)
ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Context context)
{
return parameters;
return StaticCast<Cci.IParameterTypeInformation>.From(parameters);
}
bool Cci.ISignature.ReturnValueIsModified
......
......@@ -98,9 +98,9 @@ System.Reflection.MethodImplAttributes Cci.IMethodDefinition.GetImplementationAt
return System.Reflection.MethodImplAttributes.Managed | System.Reflection.MethodImplAttributes.Runtime;
}
IEnumerable<Cci.IParameterDefinition> Cci.IMethodDefinition.Parameters
ImmutableArray<Cci.IParameterDefinition> Cci.IMethodDefinition.Parameters
{
get { return SpecializedCollections.EmptyEnumerable<Cci.IParameterDefinition>(); }
get { return ImmutableArray<Cci.IParameterDefinition>.Empty; }
}
Cci.IPlatformInvokeInformation Cci.IMethodDefinition.PlatformInvokeData
......@@ -193,9 +193,9 @@ Cci.IMethodDefinition Cci.IMethodReference.GetResolvedMethod(Context context)
return this;
}
IEnumerable<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
ImmutableArray<Cci.IParameterTypeInformation> Cci.IMethodReference.ExtraParameters
{
get { return SpecializedCollections.EmptyEnumerable<Cci.IParameterTypeInformation>(); }
get { return ImmutableArray<Cci.IParameterTypeInformation>.Empty; }
}
Cci.IGenericMethodInstanceReference Cci.IMethodReference.AsGenericMethodInstanceReference
......@@ -218,9 +218,9 @@ ushort Cci.ISignature.ParameterCount
get { return 0; }
}
IEnumerable<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Context context)
ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(Context context)
{
return SpecializedCollections.EmptyEnumerable<Cci.IParameterTypeInformation>();
return ImmutableArray<Cci.IParameterTypeInformation>.Empty;
}
IEnumerable<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
......
// 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.Generic;
using System.Collections.Immutable;
namespace Microsoft.Cci
{
......@@ -12,7 +13,7 @@ internal interface ICustomAttribute
/// <summary>
/// Zero or more positional arguments for the attribute constructor.
/// </summary>
IEnumerable<IMetadataExpression> GetArguments(Microsoft.CodeAnalysis.Emit.Context context);
ImmutableArray<IMetadataExpression> GetArguments(Microsoft.CodeAnalysis.Emit.Context context);
/// <summary>
/// A reference to the constructor that will be used to instantiate this custom attribute during execution (if the attribute is inspected via Reflection).
......@@ -22,7 +23,7 @@ internal interface ICustomAttribute
/// <summary>
/// Zero or more named arguments that specify values for fields and properties of the attribute.
/// </summary>
IEnumerable<IMetadataNamedArgument> GetNamedArguments(Microsoft.CodeAnalysis.Emit.Context context);
ImmutableArray<IMetadataNamedArgument> GetNamedArguments(Microsoft.CodeAnalysis.Emit.Context context);
/// <summary>
/// The number of positional arguments.
......
......@@ -367,7 +367,7 @@ internal interface IMethodBody
/// <summary>
/// A list exception data within the method body IL.
/// </summary>
IEnumerable<ExceptionHandlerRegion> ExceptionRegions
ImmutableArray<ExceptionHandlerRegion> ExceptionRegions
{
get;
......@@ -382,7 +382,7 @@ IEnumerable<ExceptionHandlerRegion> ExceptionRegions
/// <summary>
/// The local variables of the method.
/// </summary>
IEnumerable<ILocalDefinition> LocalVariables { get; }
ImmutableArray<ILocalDefinition> LocalVariables { get; }
/// <summary>
/// The definition of the method whose body this is.
......@@ -567,7 +567,7 @@ bool IsVirtual
/// <summary>
/// The parameters forming part of this signature.
/// </summary>
IEnumerable<IParameterDefinition> Parameters { get; }
ImmutableArray<IParameterDefinition> Parameters { get; }
/// <summary>
/// Detailed information about the PInvoke stub. Identifies which method to call, which module has the method and the calling convention among other things.
......@@ -727,7 +727,7 @@ IMetadataConstant DefaultValue
/// <summary>
/// The parameters forming part of this signature.
/// </summary>
IEnumerable<IParameterDefinition> Parameters { get; }
ImmutableArray<IParameterDefinition> Parameters { get; }
/// <summary>
/// The method used to set the value of this property. May be absent (null).
......@@ -754,7 +754,7 @@ internal interface ISignature
/// <summary>
/// The parameters forming part of this signature.
/// </summary>
IEnumerable<IParameterTypeInformation> GetParameters(Microsoft.CodeAnalysis.Emit.Context context);
ImmutableArray<IParameterTypeInformation> GetParameters(Microsoft.CodeAnalysis.Emit.Context context);
/// <summary>
/// Returns the list of custom modifiers, if any, associated with the returned value. Evaluate this property only if ReturnValueIsModified is true.
......@@ -906,7 +906,7 @@ ushort GenericParameterCount
/// <summary>
/// Information about this types of the extra arguments supplied at the call sites that references the method with this object.
/// </summary>
IEnumerable<IParameterTypeInformation> ExtraParameters { get; }
ImmutableArray<IParameterTypeInformation> ExtraParameters { get; }
IGenericMethodInstanceReference AsGenericMethodInstanceReference { get; }
ISpecializedMethodReference AsSpecializedMethodReference { get; }
......
......@@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using Roslyn.Utilities;
using Cci = Microsoft.Cci;
using System.Collections.Immutable;
namespace Microsoft.Cci
{
......@@ -332,7 +333,7 @@ public virtual void Visit(IGlobalMethodDefinition globalMethodDefinition)
/// Visits the specified local definitions.
/// </summary>
/// <param name="localDefinitions">The local definitions.</param>
public void Visit(IEnumerable<ILocalDefinition> localDefinitions)
public void Visit(ImmutableArray<ILocalDefinition> localDefinitions)
{
foreach (ILocalDefinition localDefinition in localDefinitions)
{
......@@ -643,7 +644,7 @@ public virtual void Visit(INestedTypeReference nestedTypeReference)
/// <summary>
/// Visits the specified operation exception informations.
/// </summary>
public void Visit(IEnumerable<ExceptionHandlerRegion> exceptionRegions)
public void Visit(ImmutableArray<ExceptionHandlerRegion> exceptionRegions)
{
foreach (ExceptionHandlerRegion region in exceptionRegions)
{
......@@ -667,7 +668,7 @@ public virtual void Visit(ExceptionHandlerRegion exceptionRegion)
/// Visits the specified parameters.
/// </summary>
/// <param name="parameters">The parameters.</param>
public void Visit(IEnumerable<IParameterDefinition> parameters)
public void Visit(ImmutableArray<IParameterDefinition> parameters)
{
foreach (IParameterDefinition parameter in parameters)
{
......@@ -712,7 +713,7 @@ public virtual void Visit(IParameterDefinition parameterDefinition)
/// Visits the specified parameter type informations.
/// </summary>
/// <param name="parameterTypeInformations">The parameter type informations.</param>
public void Visit(IEnumerable<IParameterTypeInformation> parameterTypeInformations)
public void Visit(ImmutableArray<IParameterTypeInformation> parameterTypeInformations)
{
foreach (IParameterTypeInformation parameterTypeInformation in parameterTypeInformations)
{
......
......@@ -13,15 +13,6 @@ namespace Microsoft.Cci
/// </summary>
internal static class IteratorHelper
{
/// <summary>
/// Returns an enumerable containing no objects.
/// </summary>
/// <returns></returns>
public static IEnumerable<T> GetEmptyEnumerable<T>()
{
return SpecializedCollections.EmptyEnumerable<T>();
}
/// <summary>
/// True if the given enumerable is not null and contains at least one element.
/// </summary>
......
......@@ -2204,7 +2204,7 @@ private uint GetPropertySignatureIndex(IPropertyDefinition propertyDef)
MemoryStream sig = MemoryStream.GetInstance();
BinaryWriter writer = new BinaryWriter(sig);
this.SerializeSignature(propertyDef, 0, IteratorHelper.GetEmptyEnumerable<IParameterTypeInformation>(), writer);
this.SerializeSignature(propertyDef, 0, ImmutableArray<IParameterTypeInformation>.Empty, writer);
result = this.GetBlobIndex(sig.ToArray());
this.signatureIndex.Add(propertyDef, result);
sig.Free();
......@@ -3005,7 +3005,8 @@ private uint SerializeLocalVariableSignatureAndReturnToken(IMethodBody methodBod
{
Debug.Assert(!this.tableIndicesAreComplete);
this.localDefIndex.Clear();
ushort numLocals = (ushort)IteratorHelper.EnumerableCount(methodBody.LocalVariables);
var locals = methodBody.LocalVariables;
ushort numLocals = (ushort)locals.Length;
if (numLocals == 0)
{
return 0;
......@@ -5163,7 +5164,7 @@ private void SerializeMethodBody(IMethodBody methodBody, BinaryWriter writer)
byte[] il = this.SerializeMethodBodyIL(methodBody);
uint numberOfExceptionHandlers = IteratorHelper.EnumerableCount(methodBody.ExceptionRegions);
uint numberOfExceptionHandlers = (uint)methodBody.ExceptionRegions.Length;
if (il.Length < 64 && methodBody.MaxStack <= 8 && localVariableSignatureToken == 0 && numberOfExceptionHandlers == 0)
{
//If 'possiblyDuplicateMethodBodies' is not null, check if an identical
......@@ -5308,7 +5309,7 @@ private void SerializeDebugInfo(IMethodBody methodBody, uint ilLength)
private void SerializeReferenceToMethodWithModuleInfo()
{
MemoryStream customMetadata = new MemoryStream();
MemoryStream customMetadata = new MemoryStream(12);
BinaryWriter cmw = new BinaryWriter(customMetadata);
cmw.WriteByte(4); // version
cmw.WriteByte(2); // kind: ForwardToModuleInfo
......@@ -5320,7 +5321,7 @@ private void SerializeReferenceToMethodWithModuleInfo()
private void SerializeReferenceToPreviousMethodWithUsingInfo()
{
MemoryStream customMetadata = new MemoryStream();
MemoryStream customMetadata = new MemoryStream(12);
BinaryWriter cmw = new BinaryWriter(customMetadata);
cmw.WriteByte(4); // version
cmw.WriteByte(1); // kind: ForwardInfo
......@@ -5823,7 +5824,8 @@ private void DefineScopeLocals(ILocalScope currentScope)
private void SerializeMethodBodyExceptionHandlerTable(IMethodBody methodBody, uint numberOfExceptionHandlers, BinaryWriter writer)
{
bool useSmallExceptionHeaders = MayUseSmallExceptionHeaders(numberOfExceptionHandlers, methodBody.ExceptionRegions);
var regions = methodBody.ExceptionRegions;
bool useSmallExceptionHeaders = MayUseSmallExceptionHeaders(numberOfExceptionHandlers, regions);
writer.Align(4);
if (useSmallExceptionHeaders)
{
......@@ -5840,7 +5842,7 @@ private void SerializeMethodBodyExceptionHandlerTable(IMethodBody methodBody, ui
writer.WriteUshort((ushort)((dataSize >> 8) & 0xffff));
}
foreach (var region in methodBody.ExceptionRegions)
foreach (var region in regions)
{
this.SerializeExceptionRegion(region, useSmallExceptionHeaders, writer);
}
......@@ -5876,7 +5878,7 @@ private void SerializeExceptionRegion(ExceptionHandlerRegion region, bool useSma
}
}
private static bool MayUseSmallExceptionHeaders(uint numberOfExceptionHandlers, IEnumerable<ExceptionHandlerRegion> exceptionRegions)
private static bool MayUseSmallExceptionHeaders(uint numberOfExceptionHandlers, ImmutableArray<ExceptionHandlerRegion> exceptionRegions)
{
if (numberOfExceptionHandlers * 12 + 4 > 0xff)
{
......@@ -6444,7 +6446,7 @@ private void SerializePermissionSet(IEnumerable<ICustomAttribute> permissionSet,
// TODO: xml for older platforms
}
private void SerializeSignature(ISignature signature, ushort genericParameterCount, IEnumerable<IParameterTypeInformation> extraArgumentTypes, BinaryWriter writer)
private void SerializeSignature(ISignature signature, ushort genericParameterCount, ImmutableArray<IParameterTypeInformation> extraArgumentTypes, BinaryWriter writer)
{
byte header = (byte)signature.CallingConvention;
if (signature is IPropertyDefinition)
......@@ -6458,8 +6460,9 @@ private void SerializeSignature(ISignature signature, ushort genericParameterCou
writer.WriteCompressedUInt(genericParameterCount);
}
uint numberOfRequiredParameters = IteratorHelper.EnumerableCount(signature.GetParameters(Context));
uint numberOfOptionalParameters = IteratorHelper.EnumerableCount(extraArgumentTypes);
var @params = signature.GetParameters(Context);
uint numberOfRequiredParameters = (uint)@params.Length;
uint numberOfOptionalParameters = (uint)extraArgumentTypes.Length;
writer.WriteCompressedUInt(numberOfRequiredParameters + numberOfOptionalParameters);
if (signature.ReturnValueIsModified)
{
......@@ -6475,7 +6478,7 @@ private void SerializeSignature(ISignature signature, ushort genericParameterCou
}
this.SerializeTypeReference(signature.GetType(Context), writer, false, true);
foreach (IParameterTypeInformation parameterTypeInformation in signature.GetParameters(Context))
foreach (IParameterTypeInformation parameterTypeInformation in @params)
{
this.SerializeParameterInformation(parameterTypeInformation, writer);
}
......
// 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.Generic;
using System.Collections.Immutable;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
......@@ -147,7 +148,7 @@ internal interface IFunctionPointerTypeReference : ITypeReference, ISignature
/// <summary>
/// The types and modifiers of extra arguments that the caller will pass to the methods that are pointed to by this pointer.
/// </summary>
IEnumerable<IParameterTypeInformation> ExtraArgumentTypes { get; }
ImmutableArray<IParameterTypeInformation> ExtraArgumentTypes { get; }
}
/// <summary>
......
......@@ -17,8 +17,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Partial Class VisualBasicAttributeData
Implements Cci.ICustomAttribute
Private Function GetArguments1(context As Microsoft.CodeAnalysis.Emit.Context) As IEnumerable(Of Cci.IMetadataExpression) Implements Cci.ICustomAttribute.GetArguments
Return From arg In CommonConstructorArguments Select CreateMetadataExpression(arg, context)
Private Function GetArguments1(context As Microsoft.CodeAnalysis.Emit.Context) As ImmutableArray(Of Cci.IMetadataExpression) Implements Cci.ICustomAttribute.GetArguments
Return CommonConstructorArguments.SelectAsArray(Function(arg) CreateMetadataExpression(arg, context))
End Function
Private Function Constructor1(context As Microsoft.CodeAnalysis.Emit.Context) As Cci.IMethodReference Implements Cci.ICustomAttribute.Constructor
......@@ -27,8 +27,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
syntaxNodeOpt:=DirectCast(context.SyntaxNodeOpt, VisualBasicSyntaxNode), Diagnostics:=context.Diagnostics)
End Function
Private Function GetNamedArguments1(context As Microsoft.CodeAnalysis.Emit.Context) As IEnumerable(Of Cci.IMetadataNamedArgument) Implements Cci.ICustomAttribute.GetNamedArguments
Return From namedArgument In CommonNamedArguments Select CreateMetadataNamedArgument(namedArgument.Key, namedArgument.Value, context)
Private Function GetNamedArguments1(context As Microsoft.CodeAnalysis.Emit.Context) As ImmutableArray(Of Cci.IMetadataNamedArgument) Implements Cci.ICustomAttribute.GetNamedArguments
Return CommonNamedArguments.SelectAsArray(Function(namedArgument) CreateMetadataNamedArgument(namedArgument.Key, namedArgument.Value, context))
End Function
Private ReadOnly Property ArgumentCount As Integer Implements Cci.ICustomAttribute.ArgumentCount
......
......@@ -2,6 +2,7 @@
Imports System
Imports System.Collections.Generic
Imports System.Collections.Immutable
Imports System.Linq
Imports System.Text
Imports Microsoft.CodeAnalysis.Text
......@@ -53,9 +54,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return Nothing
End Function
Private ReadOnly Property IMethodReferenceExtraParameters As IEnumerable(Of Microsoft.Cci.IParameterTypeInformation) Implements Microsoft.Cci.IMethodReference.ExtraParameters
Private ReadOnly Property IMethodReferenceExtraParameters As ImmutableArray(Of Microsoft.Cci.IParameterTypeInformation) Implements Microsoft.Cci.IMethodReference.ExtraParameters
Get
Return SpecializedCollections.EmptyEnumerable(Of Microsoft.Cci.IParameterTypeInformation)()
Return ImmutableArray(Of Microsoft.Cci.IParameterTypeInformation).Empty
End Get
End Property
......@@ -65,7 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
End Get
End Property
Private Function ISignatureGetParameters(context As Microsoft.CodeAnalysis.Emit.Context) As IEnumerable(Of Microsoft.Cci.IParameterTypeInformation) Implements Microsoft.Cci.ISignature.GetParameters
Private Function ISignatureGetParameters(context As Microsoft.CodeAnalysis.Emit.Context) As ImmutableArray(Of Microsoft.Cci.IParameterTypeInformation) Implements Microsoft.Cci.ISignature.GetParameters
Dim moduleBeingBuilt As PEModuleBuilder = DirectCast(context.Module, PEModuleBuilder)
Return moduleBeingBuilt.Translate(m_UnderlyingMethod.Parameters)
......
......@@ -135,9 +135,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return Nothing
End Function
Private ReadOnly Property IMethodReferenceExtraParameters As IEnumerable(Of IParameterTypeInformation) Implements IMethodReference.ExtraParameters
Private ReadOnly Property IMethodReferenceExtraParameters As ImmutableArray(Of IParameterTypeInformation) Implements IMethodReference.ExtraParameters
Get
Return SpecializedCollections.EmptyEnumerable(Of IParameterTypeInformation)()
Return ImmutableArray(Of IParameterTypeInformation).Empty
End Get
End Property
......@@ -147,7 +147,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Get
End Property
Private Function ISignatureGetParameters(context As Microsoft.CodeAnalysis.Emit.Context) As IEnumerable(Of IParameterTypeInformation) Implements ISignature.GetParameters
Private Function ISignatureGetParameters(context As Microsoft.CodeAnalysis.Emit.Context) As ImmutableArray(Of IParameterTypeInformation) Implements ISignature.GetParameters
Dim moduleBeingBuilt As PEModuleBuilder = DirectCast(context.Module, PEModuleBuilder)
Debug.Assert(Me.IsDefinitionOrDistinct())
......@@ -158,16 +158,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
#End If
If Me.IsDefinition AndAlso Me.ContainingModule = moduleBeingBuilt.SourceModule Then
Return EnumerateDefinitionParameters
Return EnumerateDefinitionParameters()
Else
Return moduleBeingBuilt.Translate(Me.Parameters)
End If
End Function
Private Function EnumerateDefinitionParameters() As IEnumerable(Of Cci.IParameterTypeInformation)
Private Function EnumerateDefinitionParameters() As ImmutableArray(Of Cci.IParameterTypeInformation)
Debug.Assert(Me.Parameters.All(Function(p) p.IsDefinition))
Return Me.Parameters
Return StaticCast(Of IParameterTypeInformation).From(Me.Parameters)
End Function
Private ReadOnly Property ISignatureReturnValueCustomModifiers As IEnumerable(Of Microsoft.Cci.ICustomModifier) Implements ISignature.ReturnValueCustomModifiers
......@@ -435,7 +435,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Get
End Property
Private ReadOnly Property IMethodDefinitionParameters As IEnumerable(Of IParameterDefinition) Implements IMethodDefinition.Parameters
Private ReadOnly Property IMethodDefinitionParameters As ImmutableArray(Of IParameterDefinition) Implements IMethodDefinition.Parameters
Get
CheckDefinitionInvariant()
......@@ -444,7 +444,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Debug.Assert(p Is p.OriginalDefinition)
Next
#End If
Return Me.Parameters
Return StaticCast(Of IParameterDefinition).From(Me.Parameters)
End Get
End Property
......
......@@ -2,6 +2,7 @@
Imports System
Imports System.Collections.Generic
Imports System.Collections.Immutable
Imports Microsoft.Cci
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Emit
......@@ -71,10 +72,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Get
End Property
Private ReadOnly Property IPropertyDefinitionParameters As IEnumerable(Of IParameterDefinition) Implements IPropertyDefinition.Parameters
Private ReadOnly Property IPropertyDefinitionParameters As ImmutableArray(Of IParameterDefinition) Implements IPropertyDefinition.Parameters
Get
CheckDefinitionInvariant()
Return Me.GetParameters()
Return StaticCast(Of IParameterDefinition).From(Me.Parameters)
End Get
End Property
......@@ -99,9 +100,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Get
End Property
Private Function ISignatureGetParameters(context As Microsoft.CodeAnalysis.Emit.Context) As IEnumerable(Of IParameterTypeInformation) Implements ISignature.GetParameters
Private Function ISignatureGetParameters(context As Microsoft.CodeAnalysis.Emit.Context) As ImmutableArray(Of IParameterTypeInformation) Implements ISignature.GetParameters
CheckDefinitionInvariant()
Return Me.GetParameters()
Return StaticCast(Of IParameterTypeInformation).From(Me.Parameters)
End Function
Private ReadOnly Property ISignatureReturnValueCustomModifiers As IEnumerable(Of Microsoft.Cci.ICustomModifier) Implements ISignature.ReturnValueCustomModifiers
......@@ -165,12 +166,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return Me.MetadataName
End Get
End Property
Private Function GetParameters() As IEnumerable(Of ParameterSymbol)
CheckDefinitionInvariant()
Return Me.Parameters
End Function
End Class
End Namespace
......@@ -402,19 +402,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return methodRef
End Function
Friend Overloads Function Translate(params As ImmutableArray(Of ParameterSymbol)) As IEnumerable(Of Microsoft.Cci.IParameterTypeInformation)
Friend Overloads Function Translate(params As ImmutableArray(Of ParameterSymbol)) As ImmutableArray(Of Microsoft.Cci.IParameterTypeInformation)
Debug.Assert(params.All(Function(p) p.IsDefinitionOrDistinct()))
If (params.Length = 0) Then
Return SpecializedCollections.EmptyEnumerable(Of Cci.IParameterTypeInformation)()
End If
Dim firstParam = params.First()
Dim mustBeTranslated = MustBeWrapped(firstParam)
Dim mustBeTranslated = params.Any AndAlso MustBeWrapped(params.First())
Debug.Assert(params.All(Function(p) mustBeTranslated = MustBeWrapped(p)), "either all or no parameters need translating")
If (Not mustBeTranslated) Then
Return params
Return StaticCast(Of Microsoft.Cci.IParameterTypeInformation).From(params)
End If
Return TranslateAll(params)
......@@ -437,10 +432,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return False
End Function
Private Iterator Function TranslateAll(params As ImmutableArray(Of ParameterSymbol)) As IEnumerable(Of Microsoft.Cci.IParameterTypeInformation)
For Each param In params
Yield CreateParameterTypeInformationWrapper(param)
Next
Private Function TranslateAll(params As ImmutableArray(Of ParameterSymbol)) As ImmutableArray(Of Microsoft.Cci.IParameterTypeInformation)
Return params.SelectAsArray(Function(param) CreateParameterTypeInformationWrapper(param))
End Function
Private Function CreateParameterTypeInformationWrapper(param As ParameterSymbol) As Cci.IParameterTypeInformation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册