Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

29 changes: 1 addition & 28 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,26 +1211,6 @@ public void Add(IEnumerable<T> items)
}
}

/// <summary>
/// Special add for TypeTable type entries that removes redundant file entries.
/// </summary>
internal void AddTypeTableTypesInfo(IEnumerable<T> items)
{
if (typeof(T) != typeof(SessionStateTypeEntry)) { throw new PSInvalidOperationException(); }

lock (_syncObject)
{
foreach (var element in items)
{
if (element is SessionStateTypeEntry typeEntry && typeEntry.TypeData != null)
{
// Skip type file entries.
_internalCollection.Add(element);
}
}
}
}

/// <summary>
/// Get enumerator for this collection.
/// </summary>
Expand Down Expand Up @@ -3460,12 +3440,7 @@ internal void UpdateTypes(ExecutionContext context, bool updateOnly)
context.TypeTable = typeTable;

Types.Clear();

// A TypeTable contains types info along with type file references used to create the types info,
// which is redundant information. When resused in a runspace the ISS unpacks the file types again
// resulting in duplicate types and duplication errors when processed.
// So use this special Add method to filter all types files found in the TypeTable.
Types.AddTypeTableTypesInfo(typeTable.typesInfo);
Types.Add(typeTable.typesInfo);

return;
}
Expand All @@ -3482,7 +3457,6 @@ internal void UpdateTypes(ExecutionContext context, bool updateOnly)
ConcurrentDictionary<string, string> filesProcessed
= new ConcurrentDictionary<string, string>(/*concurrencyLevel*/3, /*capacity*/3, StringComparer.OrdinalIgnoreCase);
Parallel.ForEach(Types, sste =>
// foreach (var sste in Types)
{
if (sste.FileName != null)
{
Expand Down Expand Up @@ -3510,7 +3484,6 @@ ConcurrentDictionary<string, string> filesProcessed
context.TypeTable.Update(sste.TypeData, errors, sste.IsRemove);
}
});
// }

context.TypeTable.ClearConsolidatedMembers();

Expand Down
52 changes: 45 additions & 7 deletions src/System.Management.Automation/engine/MshMemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,7 @@ public PSMemberSet(string name)
{
if (string.IsNullOrEmpty(name))
{
throw PSTraceSource.NewArgumentException("name");
throw PSTraceSource.NewArgumentException(nameof(name));
}

this.name = name;
Expand All @@ -3080,21 +3080,21 @@ public PSMemberSet(string name, IEnumerable<PSMemberInfo> members)
{
if (string.IsNullOrEmpty(name))
{
throw PSTraceSource.NewArgumentException("name");
throw PSTraceSource.NewArgumentException(nameof(name));
}

this.name = name;
if (members == null)
{
throw PSTraceSource.NewArgumentNullException("members");
throw PSTraceSource.NewArgumentNullException(nameof(members));
}

this.internalMembers = new PSMemberInfoInternalCollection<PSMemberInfo>();
foreach (PSMemberInfo member in members)
{
if (member == null)
{
throw PSTraceSource.NewArgumentNullException("members");
throw PSTraceSource.NewArgumentNullException(nameof(members));
}

this.internalMembers.Add(member.Copy());
Expand All @@ -3105,6 +3105,26 @@ public PSMemberSet(string name, IEnumerable<PSMemberInfo> members)
_methods = new PSMemberInfoIntegratingCollection<PSMethodInfo>(this, s_emptyMethodCollection);
}

/// <summary>
/// Initializes a new instance of PSMemberSet with all the initial members in <paramref name="members"/>.
/// This constructor is supposed to be used in TypeTable to reuse the passed-in member collection.
/// Null-argument check is skipped here, so callers need to check arguments before passing in.
/// </summary>
/// <param name="name">Name for the member set.</param>
/// <param name="members">Members in the member set.</param>
internal PSMemberSet(string name, PSMemberInfoInternalCollection<PSMemberInfo> members)
{
Diagnostics.Assert(!string.IsNullOrEmpty(name), "Caller needs to guarantee not null or empty.");
Diagnostics.Assert(members != null, "Caller needs to guarantee not null.");

this.name = name;
this.internalMembers = members;

_members = new PSMemberInfoIntegratingCollection<PSMemberInfo>(this, s_emptyMemberCollection);
_properties = new PSMemberInfoIntegratingCollection<PSPropertyInfo>(this, s_emptyPropertyCollection);
_methods = new PSMemberInfoIntegratingCollection<PSMethodInfo>(this, s_emptyMethodCollection);
}

private static readonly Collection<CollectionEntry<PSMemberInfo>> s_typeMemberCollection = GetTypeMemberCollection();
private static readonly Collection<CollectionEntry<PSMethodInfo>> s_typeMethodCollection = GetTypeMethodCollection();
private static readonly Collection<CollectionEntry<PSPropertyInfo>> s_typePropertyCollection = GetTypePropertyCollection();
Expand Down Expand Up @@ -3434,27 +3454,45 @@ public PSPropertySet(string name, IEnumerable<string> referencedPropertyNames)
{
if (string.IsNullOrEmpty(name))
{
throw PSTraceSource.NewArgumentException("name");
throw PSTraceSource.NewArgumentException(nameof(name));
}

this.name = name;
if (referencedPropertyNames == null)
{
throw PSTraceSource.NewArgumentNullException("referencedPropertyNames");
throw PSTraceSource.NewArgumentNullException(nameof(referencedPropertyNames));
}

ReferencedPropertyNames = new Collection<string>();
foreach (string referencedPropertyName in referencedPropertyNames)
{
if (string.IsNullOrEmpty(referencedPropertyName))
{
throw PSTraceSource.NewArgumentException("referencedPropertyNames");
throw PSTraceSource.NewArgumentException(nameof(referencedPropertyNames));
}

ReferencedPropertyNames.Add(referencedPropertyName);
}
}

/// <summary>
/// Initializes a new instance of PSPropertySet with a name and list of property names.
/// This constructor is supposed to be used in TypeTable to reuse the passed-in property name list.
/// Null-argument check is skipped here, so callers need to check arguments before passing in.
/// </summary>
/// <param name="name">Name of the set.</param>
/// <param name="referencedPropertyNameList">Name of the properties in the set.</param>
internal PSPropertySet(string name, List<string> referencedPropertyNameList)
{
Diagnostics.Assert(!string.IsNullOrEmpty(name), "Caller needs to guarantee not null or empty.");
Diagnostics.Assert(referencedPropertyNameList != null, "Caller needs to guarantee not null.");

// We use the constructor 'public Collection(IList<T> list)' to create the collection,
// so that the passed-in list is directly used as the backing store of the collection.
this.name = name;
ReferencedPropertyNames = new Collection<string>(referencedPropertyNameList);
}

/// <summary>
/// Gets the property names in this property set.
/// </summary>
Expand Down
Loading