Skip to content
Merged
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
19 changes: 13 additions & 6 deletions src/DotNetty.Common/Utilities/AttributeKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace DotNetty.Common.Utilities
{
using System;

internal static class AttributeKey
{
// Keep the instance of AttributeConstantPool out of generic classes, to make it an really singleton for different generic types.
// see https://github.com/Azure/DotNetty/issues/498
public static readonly ConstantPool Pool = new AttributeConstantPool();

sealed class AttributeConstantPool : ConstantPool
{
protected override IConstant NewConstant<TValue>(int id, string name) => new AttributeKey<TValue>(id, name);
};
}

/// <summary>
/// Key which can be used to access <seealso cref="Attribute" /> out of the <see cref="IAttributeMap" />. Be aware that
/// it is not be possible to have multiple keys with the same name.
Expand All @@ -14,12 +26,7 @@ namespace DotNetty.Common.Utilities
/// </typeparam>
public sealed class AttributeKey<T> : AbstractConstant<AttributeKey<T>>
{
public static readonly ConstantPool Pool = new AttributeConstantPool();

sealed class AttributeConstantPool : ConstantPool
{
protected override IConstant NewConstant<TValue>(int id, string name) => new AttributeKey<TValue>(id, name);
};
public static readonly ConstantPool Pool = AttributeKey.Pool;

/// <summary>Returns the singleton instance of the {@link AttributeKey} which has the specified <c>name</c>.</summary>
public static AttributeKey<T> ValueOf(string name) => (AttributeKey<T>)Pool.ValueOf<T>(name);
Expand Down