Skip to content

Commit

Permalink
Fix #498 (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyjdelete authored and nayato committed Oct 21, 2019
1 parent 780acdb commit c011350
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit c011350

Please sign in to comment.