mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use HashSet instead of Hashtable with null values (#12958)
This commit is contained in:
+7
-7
@@ -588,7 +588,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
/// <returns></returns>
|
||||
internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo)
|
||||
{
|
||||
Hashtable allTypes = new Hashtable(StringComparer.OrdinalIgnoreCase);
|
||||
var allTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (TypeOrGroupReference r in appliesTo.referenceList)
|
||||
{
|
||||
@@ -596,8 +596,8 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
TypeReference tr = r as TypeReference;
|
||||
if (tr != null)
|
||||
{
|
||||
if (!allTypes.ContainsKey(tr.name))
|
||||
allTypes.Add(tr.name, null);
|
||||
if (!allTypes.Contains(tr.name))
|
||||
allTypes.Add(tr.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -616,16 +616,16 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
// we found the group, go over it
|
||||
foreach (TypeReference x in tgd.typeReferenceList)
|
||||
{
|
||||
if (!allTypes.ContainsKey(x.name))
|
||||
allTypes.Add(x.name, null);
|
||||
if (!allTypes.Contains(x.name))
|
||||
allTypes.Add(x.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppliesTo retVal = new AppliesTo();
|
||||
foreach (DictionaryEntry x in allTypes)
|
||||
foreach (string x in allTypes)
|
||||
{
|
||||
retVal.AddAppliesToType(x.Key as string);
|
||||
retVal.AddAppliesToType(x);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
||||
@@ -231,19 +231,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
Hashtable hash = new Hashtable();
|
||||
var allMembers = new HashSet<string>();
|
||||
|
||||
// build the list of unique values: remove the possible duplicates
|
||||
// from property set expansion
|
||||
foreach (PSMemberInfo m in temporaryMemberList)
|
||||
{
|
||||
if (!hash.ContainsKey(m.Name))
|
||||
if (!allMembers.Contains(m.Name))
|
||||
{
|
||||
PSPropertyExpression ex = new PSPropertyExpression(m.Name);
|
||||
|
||||
ex._isResolved = true;
|
||||
retVal.Add(ex);
|
||||
hash.Add(m.Name, null);
|
||||
allMembers.Add(m.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
string target = helpRequest.Target;
|
||||
string pattern = target;
|
||||
Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);
|
||||
var allAliases = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (!WildcardPattern.ContainsWildcardCharacters(target))
|
||||
{
|
||||
@@ -169,12 +169,12 @@ namespace System.Management.Automation
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hashtable.ContainsKey(name))
|
||||
if (allAliases.Contains(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hashtable.Add(name, null);
|
||||
allAliases.Add(name);
|
||||
|
||||
yield return helpInfo;
|
||||
}
|
||||
@@ -216,12 +216,12 @@ namespace System.Management.Automation
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hashtable.ContainsKey(name))
|
||||
if (allAliases.Contains(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hashtable.Add(name, null);
|
||||
allAliases.Add(name);
|
||||
|
||||
yield return helpInfo;
|
||||
}
|
||||
@@ -243,12 +243,12 @@ namespace System.Management.Automation
|
||||
|
||||
HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(alias);
|
||||
|
||||
if (hashtable.ContainsKey(name))
|
||||
if (allAliases.Contains(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hashtable.Add(name, null);
|
||||
allAliases.Add(name);
|
||||
|
||||
yield return helpInfo;
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ namespace System.Management.Automation
|
||||
int countHelpInfosFound = 0;
|
||||
string target = helpRequest.Target;
|
||||
// this is for avoiding duplicate result from help output.
|
||||
Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);
|
||||
var allHelpNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
CommandSearcher searcher = GetCommandSearcherForExactMatch(target, _context);
|
||||
|
||||
@@ -453,7 +453,7 @@ namespace System.Management.Automation
|
||||
throw new PSInvalidOperationException(HelpErrors.CircularDependencyInHelpForwarding);
|
||||
}
|
||||
|
||||
if (hashtable.ContainsKey(helpName))
|
||||
if (allHelpNames.Contains(helpName))
|
||||
continue;
|
||||
|
||||
if (!Match(helpInfo, helpRequest, current))
|
||||
@@ -462,7 +462,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
|
||||
countHelpInfosFound++;
|
||||
hashtable.Add(helpName, null);
|
||||
allHelpNames.Add(helpName);
|
||||
yield return helpInfo;
|
||||
|
||||
if ((countHelpInfosFound >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0))
|
||||
@@ -1053,8 +1053,8 @@ namespace System.Management.Automation
|
||||
|
||||
int countOfHelpInfoObjectsFound = 0;
|
||||
// this is for avoiding duplicate result from help output.
|
||||
Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);
|
||||
Hashtable hiddenCommands = new Hashtable(StringComparer.OrdinalIgnoreCase);
|
||||
var set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var hiddenCommands = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (string pattern in patternList)
|
||||
{
|
||||
CommandSearcher searcher = GetCommandSearcherForSearch(pattern, _context);
|
||||
@@ -1077,15 +1077,15 @@ namespace System.Management.Automation
|
||||
{
|
||||
// this command is not visible to the user (from CommandOrigin) so
|
||||
// dont show help topic for it.
|
||||
if (!hiddenCommands.ContainsKey(helpName))
|
||||
if (!hiddenCommands.Contains(helpName))
|
||||
{
|
||||
hiddenCommands.Add(helpName, null);
|
||||
hiddenCommands.Add(helpName);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hashtable.ContainsKey(helpName))
|
||||
if (set.Contains(helpName))
|
||||
continue;
|
||||
|
||||
// filter out the helpInfo object depending on user request
|
||||
@@ -1100,7 +1100,7 @@ namespace System.Management.Automation
|
||||
continue;
|
||||
}
|
||||
|
||||
hashtable.Add(helpName, null);
|
||||
set.Add(helpName);
|
||||
countOfHelpInfoObjectsFound++;
|
||||
yield return helpInfo;
|
||||
|
||||
@@ -1130,10 +1130,10 @@ namespace System.Management.Automation
|
||||
|
||||
if (helpInfo != null && !string.IsNullOrEmpty(helpName))
|
||||
{
|
||||
if (hashtable.ContainsKey(helpName))
|
||||
if (set.Contains(helpName))
|
||||
continue;
|
||||
|
||||
if (hiddenCommands.ContainsKey(helpName))
|
||||
if (hiddenCommands.Contains(helpName))
|
||||
continue;
|
||||
|
||||
// filter out the helpInfo object depending on user request
|
||||
@@ -1148,7 +1148,7 @@ namespace System.Management.Automation
|
||||
continue;
|
||||
}
|
||||
|
||||
hashtable.Add(helpName, null);
|
||||
set.Add(helpName);
|
||||
countOfHelpInfoObjectsFound++;
|
||||
yield return helpInfo;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user