Skip to content

Commit a39a3c0

Browse files
author
Oren (electricessence)
committed
Updates to disposable.
1 parent c9e97b0 commit a39a3c0

9 files changed

Lines changed: 34 additions & 33 deletions

benchmarking/Open.Disposable.ObjectPools.Benchmarking.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Open.Diagnostics" Version="1.3.0" />
24-
<PackageReference Include="Open.Text.CSV" Version="2.0.0" />
23+
<PackageReference Include="Open.Diagnostics" Version="1.4.0" />
24+
<PackageReference Include="Open.Text.CSV" Version="2.1.0" />
2525
</ItemGroup>
2626

2727
<ItemGroup>

source/Array/InterlockedArrayObjectPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ protected override T TryRelease()
7171
return null;
7272
}
7373

74-
protected override void OnDispose(bool calledExplicitly)
74+
protected override void OnDispose()
7575
{
76-
base.OnDispose(calledExplicitly);
76+
base.OnDispose();
7777
Pool = null;
7878
MaxStored = 0;
7979
}

source/GlobalSuppressions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66

77
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "<Pending>", Scope = "type", Target = "~T:Open.Disposable.ReferenceContainer`1")]
88
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "<Pending>", Scope = "type", Target = "~T:Open.Disposable.DualReferenceContainer`1")]
9+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>", Scope = "member", Target = "~F:Open.Disposable.ObjectPoolAutoTrimmer._trimmedSize")]
10+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>", Scope = "member", Target = "~F:Open.Disposable.ObjectPoolAutoTrimmer._trimDelay")]
11+

source/ObjectPoolAutoTrimmer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected virtual void TrimInternal()
7777
_pool?.TrimTo(_trimmedSize);
7878
}
7979

80-
protected override void OnDispose(bool calledExplicitly)
80+
protected override void OnDispose()
8181
{
8282
DisposeOf(ref _trimmer);
8383

source/ObjectPoolBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ protected override void OnBeforeDispose()
122122
MaxSize = 0;
123123
}
124124

125-
protected override void OnDispose(bool calledExplicitly)
125+
protected override void OnDispose()
126126
{
127-
if (!calledExplicitly || OnDiscarded == null) return;
127+
if (OnDiscarded == null) return;
128+
128129
T d;
129130
while ((d = TryRelease()) != null) OnDiscarded(d);
130131
}

source/Open.Disposable.ObjectPools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Part of the "Open" set of libraries.</Description>
1616
<RepositoryType>git</RepositoryType>
1717
<PackageTags>objectpool, dotnet, dotnetcore, cs, idisposable, threadsafe, thread-safe</PackageTags>
1818
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
19-
<Version>2.2.0</Version>
20-
<AssemblyVersion>2.2.0.0</AssemblyVersion>
21-
<FileVersion>2.2.0.0</FileVersion>
19+
<Version>2.3.0</Version>
20+
<AssemblyVersion>2.3.0.0</AssemblyVersion>
21+
<FileVersion>2.3.0.0</FileVersion>
2222
<PackageReleaseNotes></PackageReleaseNotes>
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
</PropertyGroup>
@@ -42,7 +42,7 @@ Part of the "Open" set of libraries.</Description>
4242
</ItemGroup>
4343

4444
<ItemGroup>
45-
<PackageReference Include="Open.Disposable" Version="2.0.1" />
45+
<PackageReference Include="Open.Disposable" Version="2.1.0" />
4646
<PackageReference Include="Open.Threading.Tasks" Version="1.1.3" />
4747
<PackageReference Include="System.Threading.Channels" Version="4.5.0" />
4848
</ItemGroup>

source/Recycler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public override bool Recycle(T item)
4444
protected override void OnCloseRequested()
4545
=> _bin?.Writer.Complete();
4646

47-
protected override void OnDispose(bool calledExplicitly)
47+
protected override void OnDispose()
4848
{
49-
base.OnDispose(calledExplicitly);
50-
if (!calledExplicitly) return;
49+
base.OnDispose();
50+
5151
_bin.Writer.TryComplete();
5252
_bin = null;
5353
}

source/RecyclerBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public Task Close()
4343
return Completion;
4444
}
4545

46-
protected override void OnDispose(bool calledExplicitly)
46+
protected override void OnDispose()
4747
{
4848
OnCloseRequested();
49-
if (calledExplicitly) Target = null;
49+
Target = null;
5050
}
5151
}
5252

source/TrimmableCollectionObjectPoolBase.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ protected TrimmableCollectionObjectPoolBase(TCollection pool, Func<T> factory, A
1919

2020
public override int Count => (Pool?.Count ?? 0) + PocketCount;
2121

22-
protected override void OnDispose(bool calledExplicitly)
22+
protected override void OnDispose()
2323
{
24-
base.OnDispose(calledExplicitly); // Do not call because the following is more optimized.
25-
if (calledExplicitly) Pool = null;
24+
base.OnDispose();
25+
Pool = null;
2626
}
2727
}
2828

@@ -34,30 +34,27 @@ public abstract class TrimmableGenericCollectionObjectPoolBase<T, TCollection> :
3434
protected TrimmableGenericCollectionObjectPoolBase(TCollection pool, Func<T> factory, Action<T> recycler, Action<T> disposer, int capacity = DEFAULT_CAPACITY, bool countTrackingEnabled = true)
3535
: base(factory, recycler, disposer, capacity, countTrackingEnabled)
3636
{
37-
Pool = pool;
37+
Pool = pool ?? throw new ArgumentNullException(nameof(pool)); ;
3838
}
3939

4040
protected TCollection Pool;
4141

4242
public override int Count => Pool?.Count ?? 0;
4343

44-
protected override void OnDispose(bool calledExplicitly)
44+
protected override void OnDispose()
4545
{
46-
//base.OnDispose(calledExplicitly); // Do not call because the following is more optimized.
46+
//base.OnDispose(); // Do not call because the following is more optimized.
4747

48-
if (calledExplicitly)
49-
{
50-
var p = Pool;
51-
Pool = null;
52-
53-
if (OnDiscarded != null)
54-
{
55-
foreach (var item in p)
56-
OnDiscarded(item);
57-
}
48+
var p = Pool;
49+
Pool = null;
5850

59-
p.Clear();
51+
if (OnDiscarded != null)
52+
{
53+
foreach (var item in p)
54+
OnDiscarded(item);
6055
}
56+
57+
p.Clear();
6158
}
6259
}
6360

0 commit comments

Comments
 (0)