Use primary constructors in published projects
このコミットが含まれているのは:
1 親
531e3c3b35
コミット
46a6b25756
54ファイル変更
+210
-564
検索条件に一致するファイルはありません
@@ -148,17 +148,18 @@ internal sealed class DynamicCache<TKey, TValue>
|
||||
/// <summary>
|
||||
/// An entry to use in <see cref="DynamicCache{TKey, TValue}"/>.
|
||||
/// </summary>
|
||||
private sealed class Entry
|
||||
/// <param name="key">The key to use for the entry.</param>
|
||||
private sealed class Entry(TKey key)
|
||||
{
|
||||
/// <summary>
|
||||
/// A weak reference to the actual entry instance.
|
||||
/// </summary>
|
||||
private readonly WeakReference<TKey> reference;
|
||||
private readonly WeakReference<TKey> reference = new(key);
|
||||
|
||||
/// <summary>
|
||||
/// The hashcode of the target key (so it's available even after the key is gone).
|
||||
/// </summary>
|
||||
private readonly int hashCode;
|
||||
private readonly int hashCode = EqualityComparer<TKey>.Default.GetHashCode(key);
|
||||
|
||||
/// <summary>
|
||||
/// The last key matched from <see cref="Equals(object?)"/>, if available.
|
||||
@@ -170,16 +171,6 @@ internal sealed class DynamicCache<TKey, TValue>
|
||||
/// </summary>
|
||||
private bool isPerformingLookup;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Entry"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="key">The key to use for the entry.</param>
|
||||
public Entry(TKey key)
|
||||
{
|
||||
this.reference = new WeakReference<TKey>(key);
|
||||
this.hashCode = EqualityComparer<TKey>.Default.GetHashCode(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the current entry is alive.
|
||||
/// </summary>
|
||||
@@ -265,33 +256,19 @@ internal sealed class DynamicCache<TKey, TValue>
|
||||
/// <summary>
|
||||
/// An object reponsible for removing dead <see cref="Entry"/> instance from the table.
|
||||
/// </summary>
|
||||
private sealed class EntryRemover
|
||||
/// <remarks>
|
||||
/// Creates a new <see cref="EntryRemover"/> instance with the specified parameters.
|
||||
/// </remarks>
|
||||
/// <param name="map"><inheritdoc cref="DynamicCache{TKey, TValue}.map" path="/node()"/></param>
|
||||
/// <param name="entry">The target <see cref="Entry"/> instance to remove from <see cref="map"/>.</param>
|
||||
private sealed class EntryRemover(ConcurrentDictionary<Entry, TValue> map, Entry entry)
|
||||
{
|
||||
/// <inheritdoc cref="DynamicCache{TKey, TValue}.map"/>
|
||||
private readonly ConcurrentDictionary<Entry, TValue> map;
|
||||
|
||||
/// <summary>
|
||||
/// The target <see cref="Entry"/> instance to remove from <see cref="map"/>.
|
||||
/// </summary>
|
||||
private readonly Entry entry;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EntryRemover"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="map"><inheritdoc cref="DynamicCache{TKey, TValue}.map" path="/node()"/></param>
|
||||
/// <param name="entry"><inheritdoc cref="entry" path="/node()"/></param>
|
||||
public EntryRemover(ConcurrentDictionary<Entry, TValue> map, Entry entry)
|
||||
{
|
||||
this.map = map;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes <see cref="entry"/> from <see cref="map"/> when the current instance is finalized.
|
||||
/// Removes the target entry from the map when the current instance is finalized.
|
||||
/// </summary>
|
||||
~EntryRemover()
|
||||
{
|
||||
_ = this.map.TryRemove(this.entry, out _);
|
||||
_ = map.TryRemove(entry, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,22 +34,14 @@ internal static class EquatableArray
|
||||
/// An imutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values in the array.</typeparam>
|
||||
internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
|
||||
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
|
||||
internal readonly struct EquatableArray<T>(ImmutableArray<T> array) : IEquatable<EquatableArray<T>>, IEnumerable<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The underlying <typeparamref name="T"/> array.
|
||||
/// </summary>
|
||||
private readonly T[]? array;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EquatableArray{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
|
||||
public EquatableArray(ImmutableArray<T> array)
|
||||
{
|
||||
this.array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);
|
||||
}
|
||||
private readonly T[]? array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to an item at a specified position within the array.
|
||||
|
||||
@@ -8,6 +8,8 @@ using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
/// <summary>
|
||||
@@ -351,21 +353,13 @@ internal sealed class IndentedTextWriter : IDisposable
|
||||
/// <summary>
|
||||
/// Represents an indented block that needs to be closed.
|
||||
/// </summary>
|
||||
public struct Block : IDisposable
|
||||
/// <param name="writer">The input <see cref="IndentedTextWriter"/> instance to wrap.</param>
|
||||
public struct Block(IndentedTextWriter writer) : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IndentedTextWriter"/> instance to write to.
|
||||
/// </summary>
|
||||
private IndentedTextWriter? writer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Block"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="writer">The input <see cref="IndentedTextWriter"/> instance to wrap.</param>
|
||||
public Block(IndentedTextWriter writer)
|
||||
{
|
||||
this.writer = writer;
|
||||
}
|
||||
private IndentedTextWriter? writer = writer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
|
||||
@@ -37,19 +37,19 @@ namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of objects to pool.</typeparam>
|
||||
internal sealed class ObjectPool<T>
|
||||
/// <param name="factory">The input factory to produce <typeparamref name="T"/> items.</param>
|
||||
/// <remarks>
|
||||
/// The factory is stored for the lifetime of the pool. We will call this only when pool needs to
|
||||
/// expand. compared to "new T()", Func gives more flexibility to implementers and faster than "new T()".
|
||||
/// </remarks>
|
||||
/// <param name="size">The pool size to use.</param>
|
||||
internal sealed class ObjectPool<T>(Func<T> factory, int size)
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// The factory is stored for the lifetime of the pool. We will call this only when pool needs to
|
||||
/// expand. compared to "new T()", Func gives more flexibility to implementers and faster than "new T()".
|
||||
/// </summary>
|
||||
private readonly Func<T> factory;
|
||||
|
||||
/// <summary>
|
||||
/// The array of cached items.
|
||||
/// </summary>
|
||||
private readonly Element[] items;
|
||||
private readonly Element[] items = new Element[size - 1];
|
||||
|
||||
/// <summary>
|
||||
/// Storage for the pool objects. The first item is stored in a dedicated field
|
||||
@@ -66,17 +66,6 @@ internal sealed class ObjectPool<T>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ObjectPool{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="factory">The input factory to produce <typeparamref name="T"/> items.</param>
|
||||
/// <param name="size">The pool size to use.</param>
|
||||
public ObjectPool(Func<T> factory, int size)
|
||||
{
|
||||
this.factory = factory;
|
||||
this.items = new Element[size - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces a <typeparamref name="T"/> instance.
|
||||
/// </summary>
|
||||
@@ -131,7 +120,7 @@ internal sealed class ObjectPool<T>
|
||||
}
|
||||
}
|
||||
|
||||
return this.factory();
|
||||
return factory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする