Skip to content

Commit d047063

Browse files
committed
Less code duplication for LinksDecorators and a bit of performance boost at Facade property setter.
1 parent 497934f commit d047063

File tree

3 files changed

+14
-58
lines changed

3 files changed

+14
-58
lines changed

Platform.Data.Doublets/Decorators/LinksDecoratorBase.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public ILinks<TLink> Facade
2828
{
2929
decorator.Facade = value;
3030
}
31-
else if (Links is LinksDisposableDecoratorBase<TLink> disposableDecorator)
32-
{
33-
disposableDecorator.Facade = value;
34-
}
3531
}
3632
}
3733

Platform.Data.Doublets/Decorators/LinksDisposableDecoratorBase.cs

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,38 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Runtime.CompilerServices;
42
using Platform.Disposables;
53

64
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
5+
#pragma warning disable CA1063 // Implement IDisposable Correctly
76

87
namespace Platform.Data.Doublets.Decorators
98
{
10-
public abstract class LinksDisposableDecoratorBase<TLink> : DisposableBase, ILinks<TLink>
9+
public abstract class LinksDisposableDecoratorBase<TLink> : LinksDecoratorBase<TLink>, ILinks<TLink>, System.IDisposable
1110
{
12-
private ILinks<TLink> _facade;
13-
14-
public LinksConstants<TLink> Constants
15-
{
16-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
17-
get;
18-
}
19-
20-
public ILinks<TLink> Links
11+
protected class DisposableWithMultipleCallsAllowed : Disposable
2112
{
2213
[MethodImpl(MethodImplOptions.AggressiveInlining)]
23-
get;
24-
}
14+
public DisposableWithMultipleCallsAllowed(Disposal disposal) : base(disposal) { }
2515

26-
public ILinks<TLink> Facade
27-
{
28-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29-
get => _facade;
30-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
31-
set
16+
protected override bool AllowMultipleDisposeCalls
3217
{
33-
_facade = value;
34-
if (Links is LinksDecoratorBase<TLink> decorator)
35-
{
36-
decorator.Facade = value;
37-
}
38-
else if (Links is LinksDisposableDecoratorBase<TLink> disposableDecorator)
39-
{
40-
disposableDecorator.Facade = value;
41-
}
18+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
get => true;
4220
}
4321
}
4422

45-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
46-
protected LinksDisposableDecoratorBase(ILinks<TLink> links)
47-
{
48-
Links = links;
49-
Constants = links.Constants;
50-
Facade = this;
51-
}
52-
53-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54-
public virtual TLink Count(IList<TLink> restrictions) => Links.Count(restrictions);
55-
56-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57-
public virtual TLink Each(Func<IList<TLink>, TLink> handler, IList<TLink> restrictions) => Links.Each(handler, restrictions);
23+
protected readonly DisposableWithMultipleCallsAllowed Disposable;
5824

5925
[MethodImpl(MethodImplOptions.AggressiveInlining)]
60-
public virtual TLink Create(IList<TLink> restrictions) => Links.Create(restrictions);
26+
protected LinksDisposableDecoratorBase(ILinks<TLink> links) : base(links) => Disposable = new DisposableWithMultipleCallsAllowed(Dispose);
6127

6228
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63-
public virtual TLink Update(IList<TLink> restrictions, IList<TLink> substitution) => Links.Update(restrictions, substitution);
29+
~LinksDisposableDecoratorBase() => Disposable.Destruct();
6430

6531
[MethodImpl(MethodImplOptions.AggressiveInlining)]
66-
public virtual void Delete(IList<TLink> restrictions) => Links.Delete(restrictions);
67-
68-
protected override bool AllowMultipleDisposeCalls
69-
{
70-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
71-
get => true;
72-
}
32+
public void Dispose() => Disposable.Dispose();
7333

7434
[MethodImpl(MethodImplOptions.AggressiveInlining)]
75-
protected override void Dispose(bool manual, bool wasDisposed)
35+
protected virtual void Dispose(bool manual, bool wasDisposed)
7636
{
7737
if (!wasDisposed)
7838
{

Platform.Data.Doublets/UInt64LinksTransactionsLayer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static void EnsureTransactionAllowsWriteOperations(Transaction transactio
225225
[MethodImpl(MethodImplOptions.AggressiveInlining)]
226226
protected override void Dispose(bool manual, bool wasDisposed)
227227
{
228-
if (!wasDisposed && _layer != null && !_layer.IsDisposed)
228+
if (!wasDisposed && _layer != null && !_layer.Disposable.IsDisposed)
229229
{
230230
if (!IsCommitted && !IsReverted)
231231
{
@@ -374,7 +374,7 @@ private void PushTransitions()
374374
[MethodImpl(MethodImplOptions.AggressiveInlining)]
375375
private void TransitionsPusher()
376376
{
377-
while (!IsDisposed && _transitionsPusher != null)
377+
while (!Disposable.IsDisposed && _transitionsPusher != null)
378378
{
379379
Thread.Sleep(DefaultPushDelay);
380380
PushTransitions();

0 commit comments

Comments
 (0)