Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit ba26db7

Browse files
committed
Make ActionData a struct
1 parent ab5c076 commit ba26db7

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

src/GitHub.Exports.Reactive/Collections/TrackingCollection.cs

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ void SetAndRecalculateFilter(Func<T, int, IList<T>, bool> newFilter)
238238

239239
ActionData CheckFilter(ActionData data)
240240
{
241-
data.IsIncluded = true;
241+
var isIncluded = true;
242242
if (data.TheAction == TheAction.Remove)
243-
data.IsIncluded = false;
243+
isIncluded = false;
244244
else if (filter != null)
245-
data.IsIncluded = filter(data.Item, data.Position, this);
246-
return data;
245+
isIncluded = filter(data.Item, data.Position, this);
246+
return new ActionData(data, isIncluded);
247247
}
248248

249249
int StartQueue()
@@ -366,9 +366,9 @@ ActionData FilteredAdd(ActionData data)
366366

367367
ActionData CalculateIndexes(ActionData data)
368368
{
369-
data.Index = GetIndexFiltered(data.Item);
370-
data.IndexPivot = GetLiveListPivot(data.Position, data.List);
371-
return data;
369+
var index = GetIndexFiltered(data.Item);
370+
var indexPivot = GetLiveListPivot(data.Position, data.List);
371+
return new ActionData(data, index, indexPivot);
372372
}
373373

374374
ActionData FilteredNone(ActionData data)
@@ -866,22 +866,68 @@ public void Dispose()
866866
GC.SuppressFinalize(this);
867867
}
868868

869-
class ActionData : Tuple<TheAction, T, T, int, int, List<T>>
869+
struct ActionData
870870
{
871-
public TheAction TheAction => Item1;
872-
public T Item => Item2;
873-
public T OldItem => Item3;
874-
public int Position => Item4;
875-
public int OldPosition => Item5;
876-
public List<T> List => Item6;
871+
readonly public TheAction TheAction;
872+
readonly public int Position;
873+
readonly public int OldPosition;
874+
readonly public int Index;
875+
readonly public int IndexPivot;
876+
readonly public bool IsIncluded;
877+
readonly public T Item;
878+
readonly public T OldItem;
879+
readonly public List<T> List;
880+
881+
public ActionData(ActionData other, int index, int indexPivot)
882+
{
883+
TheAction = other.TheAction;
884+
Item = other.Item;
885+
OldItem = other.OldItem;
886+
Position = other.Position;
887+
OldPosition = other.OldPosition;
888+
List = other.List;
889+
Index = index;
890+
IndexPivot = indexPivot;
891+
IsIncluded = other.IsIncluded;
892+
}
877893

878-
public int Index { get; set; }
879-
public int IndexPivot { get; set; }
880-
public bool IsIncluded { get; set; }
894+
public ActionData(ActionData other, int position)
895+
{
896+
TheAction = other.TheAction;
897+
Item = other.Item;
898+
OldItem = other.OldItem;
899+
Position = position;
900+
OldPosition = other.OldPosition;
901+
List = other.List;
902+
Index = other.Index;
903+
IndexPivot = other.IndexPivot;
904+
IsIncluded = other.IsIncluded;
905+
}
906+
907+
public ActionData(ActionData other, bool isIncluded)
908+
{
909+
TheAction = other.TheAction;
910+
Item = other.Item;
911+
OldItem = other.OldItem;
912+
Position = other.Position;
913+
OldPosition = other.OldPosition;
914+
List = other.List;
915+
Index = other.Index;
916+
IndexPivot = other.IndexPivot;
917+
IsIncluded = isIncluded;
918+
}
881919

882920
public ActionData(TheAction action, T item, T oldItem, int position, int oldPosition, List<T> list)
883-
: base(action, item, oldItem, position, oldPosition, list)
884921
{
922+
TheAction = action;
923+
Item = item;
924+
OldItem = oldItem;
925+
Position = position;
926+
OldPosition = oldPosition;
927+
List = list;
928+
Index = -1;
929+
IndexPivot = -1;
930+
IsIncluded = false;
885931
}
886932
}
887933
}

0 commit comments

Comments
 (0)