Skip to content

Commit

Permalink
Update to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Dec 25, 2023
1 parent 46bae9d commit 553cc92
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Build
run: |
dotnet build --configuration Release
Expand All @@ -24,4 +24,4 @@ jobs:
dotnet test --configuration Release
- name: Formatting
run: |
dotnet format --verify-no-changes
dotnet format --verify-no-changes
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Build
run: |
dotnet build --configuration Release
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<None Include="$(MSBuildThisFileDirectory)\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/Kinetic/Linq/Observable.Subscribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public static IDisposable Subscribe<T>(this ObserverBuilder<T> source, Action<T>
continuation: new(onNext, onError, onCompleted),
factory: new());

public static IDisposable Subscribe<T, TStateMachine>(this ObserverBuilder<T> source, in TStateMachine stateMachine, ObserverStateMachineBox box)
public static IDisposable Subscribe<T, TStateMachine>(this ObserverBuilder<T> source, ref TStateMachine stateMachine, ObserverStateMachineBox box)
where TStateMachine : struct, IObserverStateMachine<T> =>
box.Subscribe(source, stateMachine);
box.Subscribe(source, ref stateMachine);
}

internal static class Subscribe<TResult>
Expand Down
2 changes: 1 addition & 1 deletion src/Kinetic/Linq/Observable.Then.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void OnNext(TSource value)
{
_subscription?.Dispose();
_subscription = _selector(value) is { } observable
? _box.Subscribe(observable, _continuation)
? _box.Subscribe(observable, ref _continuation)
: null;
}
catch (Exception error)
Expand Down
22 changes: 11 additions & 11 deletions src/Kinetic/Linq/ObservableView.OrderBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private interface IItem<TSelf> : IComparable<TSelf>, IDisposable
private interface IKeySelector<TItem>
where TItem : IItem<TItem>
{
public (TItem, IDisposable?) CreateItem<TStateMachine>(int index, T value, in TStateMachine stateMachine)
public (TItem, IDisposable?) CreateItem<TStateMachine>(int index, T value, ref TStateMachine stateMachine)
where TStateMachine : struct, IStateMachine<TItem>;
}

Expand All @@ -70,7 +70,7 @@ private interface IKeyComparer<TItem> : IDisposable
{
public ItemComparer<TItem>? ItemComparer { get; }

public void Initialize<TStateMachine>(in TStateMachine stateMachine)
public void Initialize<TStateMachine>(ref TStateMachine stateMachine)
where TStateMachine : struct, IStateMachine<TItem>;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public StateMachine(in TContinuation continuation, in TKeySelector keySelector,
public void Initialize(ObserverStateMachineBox box)
{
_continuation.Initialize(Box = box);
_keyComparer.Initialize(this);
_keyComparer.Initialize(ref this);
}

public void Dispose()
Expand Down Expand Up @@ -232,7 +232,7 @@ public void OnNext(ListChange<T> value)
case ListChangeAction.Insert
when value.NewIndex is var originalIndex:
{
var (item, subscription) = _keySelector.CreateItem(originalIndex, value.NewItem, this);
var (item, subscription) = _keySelector.CreateItem(originalIndex, value.NewItem, ref this);
var index = _items.BinarySearch(item, _keyComparer.ItemComparer);

if (index < 0)
Expand Down Expand Up @@ -266,7 +266,7 @@ public void OnNext(ListChange<T> value)

oldItem.Dispose();

var (newItem, subscription) = _keySelector.CreateItem(originalIndex, value.NewItem, this);
var (newItem, subscription) = _keySelector.CreateItem(originalIndex, value.NewItem, ref this);
var newIndex = _items.BinarySearch(newItem, _keyComparer.ItemComparer);

if (newIndex < 0)
Expand Down Expand Up @@ -502,7 +502,7 @@ public void Create<TContinuation>(in TContinuation continuation, ObserverStateMa
public StaticKeySelector(Func<T, TKey> keySelector) =>
_keySelector = keySelector;

public (TItem, IDisposable?) CreateItem<TStateMachine>(int index, T value, in TStateMachine stateMachinen)
public (TItem, IDisposable?) CreateItem<TStateMachine>(int index, T value, ref TStateMachine stateMachinen)
where TStateMachine : struct, IStateMachine<TItem>
{
var key = _keySelector(value);
Expand All @@ -520,14 +520,14 @@ public StaticKeySelector(Func<T, TKey> keySelector) =>
public DynamicKeySelector(ObserverBuilderFactory<T, TKey> keySelector) =>
_keySelector = keySelector;

public (DynamicItem, IDisposable?) CreateItem<TStateMachine>(int index, T value, in TStateMachine stateMachine)
public (DynamicItem, IDisposable?) CreateItem<TStateMachine>(int index, T value, ref TStateMachine stateMachine)
where TStateMachine : struct, IStateMachine<DynamicItem>
{
var item = DynamicItem.Create(default, value);
var subscription = _keySelector
.Invoke(value)
.ContinueWith<DynamicItem.StateMachineFactory, ValueTuple<DynamicItem>>(new DynamicItem.StateMachineFactory(item))
.Subscribe(stateMachine, stateMachine.Box);
.Subscribe(ref stateMachine, stateMachine.Box);

item.OriginalIndex = index;
return (item, subscription);
Expand All @@ -542,7 +542,7 @@ public DynamicKeySelector(ObserverBuilderFactory<T, TKey> keySelector) =>
public StaticKeyComparer(IComparer<TKey>? keyComparer) =>
ItemComparer = ItemComparer<TItem>.Create(keyComparer);

public void Initialize<TStateMachine>(in TStateMachine stateMachine)
public void Initialize<TStateMachine>(ref TStateMachine stateMachine)
where TStateMachine : struct, IStateMachine<TItem>
{ }

Expand All @@ -560,12 +560,12 @@ private struct DynamicKeyComparer<TItem> : IKeyComparer<TItem>
public DynamicKeyComparer(IObservable<IComparer<TKey>?> observable) =>
_observable = observable;

public void Initialize<TStateMachine>(in TStateMachine stateMachine)
public void Initialize<TStateMachine>(ref TStateMachine stateMachine)
where TStateMachine : struct, IStateMachine<TItem>
{
Debug.Assert(_subscription is null);

_subscription = stateMachine.Box.Subscribe(_observable, stateMachine);
_subscription = stateMachine.Box.Subscribe(_observable, ref stateMachine);
}

public void Dispose() =>
Expand Down
4 changes: 2 additions & 2 deletions src/Kinetic/Linq/ObservableView.SelectAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void OnNext(ListChange<TSource> value)
var item = new ObservableViewItem<TResult>(index);
var subscription = _selector(value.NewItem)
.ContinueWith<SelectorStateMachineFactory<TResult>, ObservableViewItem<TResult>>(new(item))
.Subscribe(this, _box!);
.Subscribe(ref this, _box!);

_items.Insert(item.Index, item);
item.Initialize(subscription);
Expand All @@ -130,7 +130,7 @@ public void OnNext(ListChange<TSource> value)
var newItem = new ObservableViewItem<TResult>(value.NewIndex);
var newSubscription = _selector(value.NewItem)
.ContinueWith<SelectorStateMachineFactory<TResult>, ObservableViewItem<TResult>>(new(newItem))
.Subscribe(this, _box!);
.Subscribe(ref this, _box!);

_items[index] = newItem;
newItem.Initialize(newSubscription);
Expand Down
4 changes: 2 additions & 2 deletions src/Kinetic/Linq/ObservableView.Where.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void OnNext(ListChange<T> value)
var item = new WhereStateMachineItem<T>(value.NewItem, value.NewIndex);
var subscription = _predicate(item.Item)
.ContinueWith<WherePredicateStateMachineFactory<T>, WhereStateMachineItem<T>>(new(item))
.Subscribe(this, _box!);
.Subscribe(ref this, _box!);

_items.Insert(item.Index, item);
item.Initialize(subscription);
Expand All @@ -108,7 +108,7 @@ public void OnNext(ListChange<T> value)
var newItem = new WhereStateMachineItem<T>(value.NewItem, value.NewIndex);
var newSubscription = _predicate(newItem.Item)
.ContinueWith<WherePredicateStateMachineFactory<T>, WhereStateMachineItem<T>>(new(newItem))
.Subscribe(this, _box!);
.Subscribe(ref this, _box!);

_items[index] = newItem;
newItem.Initialize(newSubscription);
Expand Down
24 changes: 12 additions & 12 deletions src/Kinetic/Linq/StateMachines/ObserverStateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public readonly struct ObserverStateMachineReference<T, TStateMachine>
private readonly ObserverStateMachineBox _box;
private readonly IntPtr _stateMachineOffset;

public ObserverStateMachineReference(ObserverStateMachineBox box, in TStateMachine stateMachine) =>
_stateMachineOffset = (_box = box).OffsetTo<T, TStateMachine>(stateMachine);
public ObserverStateMachineReference(ObserverStateMachineBox box, ref TStateMachine stateMachine) =>
_stateMachineOffset = (_box = box).OffsetTo<T, TStateMachine>(ref stateMachine);

public ref TStateMachine Target =>
ref _box.ReferenceTo<T, TStateMachine>(_stateMachineOffset);
Expand All @@ -40,12 +40,12 @@ public abstract class ObserverStateMachineBox

private protected ObserverStateMachineBox() { }

internal IntPtr OffsetTo<T, TStateMachine>(in TStateMachine stateMachine)
internal IntPtr OffsetTo<T, TStateMachine>(ref TStateMachine stateMachine)
where TStateMachine : struct, IObserverStateMachine<T>
{
var machineHost = StateMachineData;
var machinePart = MemoryMarshal.CreateSpan(
ref Unsafe.As<TStateMachine, byte>(ref Unsafe.AsRef(stateMachine)),
ref Unsafe.As<TStateMachine, byte>(ref stateMachine),
length: Unsafe.SizeOf<TStateMachine>());

var offset = (nint) Unsafe.ByteOffset(
Expand All @@ -66,17 +66,17 @@ internal ref TStateMachine ReferenceTo<T, TStateMachine>(IntPtr offset)
return ref Unsafe.As<byte, TStateMachine>(ref machinePart);
}

public IDisposable Subscribe<T, TStateMachine>(IObservable<T> observable, in TStateMachine stateMachine)
public IDisposable Subscribe<T, TStateMachine>(IObservable<T> observable, ref TStateMachine stateMachine)
where TStateMachine : struct, IObserverStateMachine<T>
{
return Subscribe(observable.ToBuilder(), stateMachine);
return Subscribe(observable.ToBuilder(), ref stateMachine);
}

public IDisposable Subscribe<T, TStateMachine>(ObserverBuilder<T> builder, in TStateMachine stateMachine)
public IDisposable Subscribe<T, TStateMachine>(ObserverBuilder<T> builder, ref TStateMachine stateMachine)
where TStateMachine : struct, IObserverStateMachine<T>
{
return builder.Build<SubscribeStateMachine<T, TStateMachine>, SubscribeBoxFactory, IDisposable>(
new(new ObserverStateMachineReference<T, TStateMachine>(this, stateMachine)), new());
new(new ObserverStateMachineReference<T, TStateMachine>(this, ref stateMachine)), new());
}

private readonly struct SubscribeStateMachine<T, TStateMachine> : IObserverStateMachine<T>
Expand Down Expand Up @@ -110,17 +110,17 @@ public SubscribeBox(in TStateMachine stateMachine) :
public void Dispose() => StateMachine.Dispose();
}

public ObserverBuilder<T> Observe<T, TStateMachine>(IObservable<T> observable, in TStateMachine stateMachine)
public ObserverBuilder<T> Observe<T, TStateMachine>(IObservable<T> observable, ref TStateMachine stateMachine)
where TStateMachine : struct, IObserverStateMachine<T>
{
return Observe(observable.ToBuilder(), stateMachine);
return Observe(observable.ToBuilder(), ref stateMachine);
}

public ObserverBuilder<T> Observe<T, TStateMachine>(ObserverBuilder<T> builder, in TStateMachine stateMachine)
public ObserverBuilder<T> Observe<T, TStateMachine>(ObserverBuilder<T> builder, ref TStateMachine stateMachine)
where TStateMachine : struct, IObserverStateMachine<T>
{
return builder.ContinueWith<ObserveStateMachineFactory<T, TStateMachine>, T>(
new(new(this, stateMachine)));
new(new(this, ref stateMachine)));
}

private readonly struct ObserveStateMachineFactory<T, TStateMachine> : IObserverStateMachineFactory<T, T>
Expand Down

0 comments on commit 553cc92

Please sign in to comment.