Skip to content

Commit 1e59d60

Browse files
author
Oren (electricessence)
committed
Prep for updated release.
1 parent 7864b99 commit 1e59d60

11 files changed

+25
-27
lines changed

source/Array/InterlockedArrayObjectPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override bool Receive(T item)
6060
{
6161
// We missed getting the first item or it wasn't there.
6262
var elements = Pool;
63-
if (elements == null) return null;
63+
if (elements is null) return null;
6464

6565
var len = elements.Length;
6666
for (var i = 0; i < MaxStored && i < len; i++)

source/Collection/CollectionWrapperObjectPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override bool Receive(T item)
4141

4242
var p = Pool;
4343
var item = p?.FirstOrDefault();
44-
if (item == null) return null;
44+
if (item is null) return null;
4545
/* Removing the first item is typically horribly inefficient but we can't make assumptions about the implementation here.
4646
* It's a trade off between potentially iterating the entire collection before removing the last item, or relying on the underlying implementation.
4747
* This implementation is in place for reference more than practice. Sub classes should override. */

source/Collection/ConcurrentQueueObjectPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public ConcurrentQueueObjectPool(Func<T> factory, int capacity = DEFAULT_CAPACIT
2626
protected override bool Receive(T item)
2727
{
2828
var p = Pool;
29-
if (p == null) return false;
29+
if (p is null) return false;
3030
p.Enqueue(item); // It's possible that the count could exceed MaxSize here, but the risk is negligble as a few over the limit won't hurt.
3131
return true;
3232
}
3333

3434
protected override T? TryRelease()
3535
{
3636
var p = Pool;
37-
if (p == null) return null;
37+
if (p is null) return null;
3838
p.TryDequeue(out var item);
3939
return item;
4040
}

source/Collection/ConcurrentStackObjectPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public ConcurrentStackObjectPool(Func<T> factory, int capacity = DEFAULT_CAPACIT
2121
protected override bool Receive(T item)
2222
{
2323
var p = Pool;
24-
if (p == null) return false;
24+
if (p is null) return false;
2525
p.Push(item); // It's possible that the count could exceed MaxSize here, but the risk is negligble as a few over the limit won't hurt.
2626
return true;
2727
}
2828

2929
protected override T? TryRelease()
3030
{
3131
var p = Pool;
32-
if (p == null) return null;
32+
if (p is null) return null;
3333
p.TryPop(out var item);
3434
return item;
3535
}

source/IObjectPool.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void Give<T>(this IObjectPool<T> target, IEnumerable<T> items)
7373
if (target is null) throw new ArgumentNullException(nameof(target));
7474
Contract.EndContractBlock();
7575

76-
if (items == null) return;
76+
if (items is null) return;
7777
foreach (var i in items)
7878
target.Give(i);
7979
}
@@ -149,7 +149,7 @@ public static async ValueTask RentAsync<T>(this IObjectPool<T> source, Func<T, V
149149
Contract.EndContractBlock();
150150

151151
var item = source.Take();
152-
await action(item);
152+
await action(item).ConfigureAwait(false);
153153
source.Give(item);
154154
}
155155

@@ -168,7 +168,7 @@ public static async ValueTask<TResult> RentAsync<T, TResult>(this IObjectPool<T>
168168
Contract.EndContractBlock();
169169

170170
var item = source.Take();
171-
var result = await action(item);
171+
var result = await action(item).ConfigureAwait(false);
172172
source.Give(item);
173173
return result;
174174
}

source/ObjectPoolBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected ObjectPoolBase(Func<T> factory, Action<T>? recycler, Action<T>? dispos
2626
/// Total number of items in the pool.
2727
/// </summary>
2828
public abstract int Count { get; }
29-
protected int PocketCount => Pocket.Value == null ? 0 : 1;
29+
protected int PocketCount => Pocket.Value is null ? 0 : 1;
3030

3131
protected readonly Action<T>? Recycler; // Before entering the pool.
3232
protected readonly Action<T>? OnDiscarded; // When not able to be used.
@@ -124,7 +124,7 @@ protected override void OnBeforeDispose()
124124

125125
protected override void OnDispose()
126126
{
127-
if (OnDiscarded == null) return;
127+
if (OnDiscarded is null) return;
128128

129129
T? d;
130130
while ((d = TryRelease()) != null) OnDiscarded(d);

source/Open.Disposable.ObjectPools.csproj

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
57
<RootNamespace>Open.Disposable</RootNamespace>
6-
<Description>
7-
A set of variations on ObjectPool implementations with differing underlying collections.
8-
9-
Part of the "Open" set of libraries.
10-
</Description>
118
<Authors>electricessence</Authors>
12-
<Company>electricessence</Company>
13-
<Product />
9+
<Description>A set of variations on ObjectPool implementations with differing underlying collections.
10+
11+
Part of the "Open" set of libraries.
12+
</Description>
1413
<Copyright>https://github.com/electricessence/Open.Disposable.ObjectPools/blob/master/LISCENSE.md</Copyright>
1514
<PackageLicenseUrl></PackageLicenseUrl>
1615
<PackageProjectUrl>https://github.com/electricessence/Open.Disposable.ObjectPools/</PackageProjectUrl>
@@ -21,7 +20,6 @@
2120
<Version>2.4.1</Version>
2221
<PackageReleaseNotes></PackageReleaseNotes>
2322
<PackageLicenseExpression>MIT</PackageLicenseExpression>
24-
<Nullable>enable</Nullable>
2523
</PropertyGroup>
2624

2725
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -43,13 +41,13 @@
4341
</ItemGroup>
4442

4543
<ItemGroup>
44+
<PackageReference Include="Open.Disposable" Version="2.4.0" />
45+
<PackageReference Include="Open.Threading.Tasks" Version="1.2.0" />
46+
<PackageReference Include="System.Threading.Channels" Version="4.7.1" />
4647
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
4748
<PrivateAssets>all</PrivateAssets>
4849
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4950
</PackageReference>
50-
<PackageReference Include="Open.Disposable" Version="2.3.0" />
51-
<PackageReference Include="Open.Threading.Tasks" Version="1.1.3" />
52-
<PackageReference Include="System.Threading.Channels" Version="4.7.1" />
5351
</ItemGroup>
5452

5553
</Project>

source/Recycler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async Task Processor(Action<T> recycleFunction)
3030
Target?.Give(item);
3131
}
3232
}
33-
while (await bin.Reader.WaitToReadAsync());
33+
while (await bin.Reader.WaitToReadAsync().ConfigureAwait(false));
3434
}
3535

3636
internal Recycler(

source/RecyclerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected RecyclerBase(
1818
IObjectPool<T> target,
1919
Action<T> recycleFunction)
2020
{
21-
if (recycleFunction == null) throw new ArgumentNullException(nameof(recycleFunction));
21+
if (recycleFunction is null) throw new ArgumentNullException(nameof(recycleFunction));
2222
Target = target ?? throw new ArgumentNullException(nameof(target));
2323
Contract.EndContractBlock();
2424

source/ReferenceContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public bool SetIfNull(T value)
3737
}
3838

3939
public bool TrySave(T value)
40-
=> _value == null
40+
=> _value is null
4141
&& null == Interlocked.CompareExchange(ref _value, value, null);
4242

4343
public T? TryRetrieve()

0 commit comments

Comments
 (0)