Skip to content

Commit 8200f37

Browse files
Rework PooledHashSet<T> to avoid acquiring a HashSet<T> for 1 item
This change reworks PooledHashSet<T> and adds two features: 1. It is now possible to pass an IEqualityComparer<T> or a HashSetPool<T> when constructing a PooledHashSet<T>. A HashSetPool<T> will be chosen based on the IEqualityComparer<T>, or a new HashSet<T> will be created if a default pool doesn't exist. 2. A HashSet<T> won't be acquired from the pool (or created) until the set would contain at least two items.
1 parent dd3344f commit 8200f37

File tree

6 files changed

+878
-34
lines changed

6 files changed

+878
-34
lines changed

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/ComponentTagHelperDescriptorProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static TagHelperDescriptor CreateNameMatchingDescriptor(
125125
{
126126
metadata.IsGeneric = true;
127127

128-
using var cascadeGenericTypeAttributes = new PooledHashSet<string>(SpecializedPools.StringHashSet.Ordinal);
128+
using var cascadeGenericTypeAttributes = new PooledHashSet<string>(StringComparer.Ordinal);
129129

130130
foreach (var attribute in type.GetAttributes())
131131
{
@@ -610,7 +610,7 @@ private static void CreateContextParameter(TagHelperDescriptorBuilder builder, s
610610
// - are not indexers
611611
private static ImmutableArray<(IPropertySymbol property, PropertyKind kind)> GetProperties(INamedTypeSymbol type)
612612
{
613-
using var names = new PooledHashSet<string>(SpecializedPools.StringHashSet.Ordinal);
613+
using var names = new PooledHashSet<string>(StringComparer.Ordinal);
614614
using var results = new PooledArrayBuilder<(IPropertySymbol, PropertyKind)>();
615615

616616
var currentType = type;

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/DefaultTagHelperDescriptorFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private static bool IsPotentialDictionaryProperty(IPropertySymbol property)
375375
private static void CollectAccessibleProperties(
376376
INamedTypeSymbol typeSymbol, ref PooledArrayBuilder<IPropertySymbol> properties)
377377
{
378-
using var names = new PooledHashSet<string>(SpecializedPools.StringHashSet.Ordinal);
378+
using var names = new PooledHashSet<string>(StringComparer.Ordinal);
379379

380380
// Traverse the type hierarchy to find all accessible properties.
381381
var currentType = typeSymbol;

0 commit comments

Comments
 (0)