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

Commit f13cac6

Browse files
committed
Cleanup ActionData
1 parent a9ff71b commit f13cac6

File tree

1 file changed

+35
-40
lines changed

1 file changed

+35
-40
lines changed

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

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public TimeSpan ProcessingDelay
7474
}
7575
}
7676

77-
7877
public TrackingCollection()
7978
{
8079
queue = new ConcurrentQueue<T>();
@@ -208,7 +207,7 @@ public T RemoveItem(T item)
208207
if (position < 0)
209208
return null;
210209

211-
var data = new ActionData(TheAction.Remove, item, null, position - 1, position, original);
210+
var data = new ActionData(TheAction.Remove, original, item, null, position - 1, position);
212211
data = CheckFilter(data);
213212
data = CalculateIndexes(data);
214213
data = SortedRemove(data);
@@ -276,22 +275,22 @@ ActionData ProcessItem(T item, List<T> list)
276275

277276
// no sorting to be done, just replacing the element in-place
278277
if (comparison == 0)
279-
ret = new ActionData(TheAction.None, item, null, idx, idx, list);
278+
ret = new ActionData(TheAction.None, list, item, null, idx, idx);
280279
else
281280
// element has moved, save the original object, because we want to update its contents and move it
282281
// but not overwrite the instance.
283-
ret = new ActionData(TheAction.Move, item, old, comparison, idx, list);
282+
ret = new ActionData(TheAction.Move, list, item, old, comparison, idx);
284283
}
285284
// the element doesn't exist yet
286285
// figure out whether we're larger than the last element or smaller than the first or
287286
// if we have to place the new item somewhere in the middle
288287
else if (list.Count > 0)
289288
{
290289
if (comparer(list[0], item) >= 0)
291-
ret = new ActionData(TheAction.Insert, item, null, 0, -1, list);
290+
ret = new ActionData(TheAction.Insert, list, item, null, 0, -1);
292291

293292
else if (comparer(list[list.Count - 1], item) <= 0)
294-
ret = new ActionData(TheAction.Add, item, null, list.Count, -1, list);
293+
ret = new ActionData(TheAction.Add, list, item, null, list.Count, -1);
295294

296295
// this happens if the original observable is not sorted, or it's sorting order doesn't
297296
// match the comparer that has been set
@@ -300,11 +299,11 @@ ActionData ProcessItem(T item, List<T> list)
300299
idx = BinarySearch(list, item, comparer);
301300
if (idx < 0)
302301
idx = ~idx;
303-
ret = new ActionData(TheAction.Insert, item, null, idx, -1, list);
302+
ret = new ActionData(TheAction.Insert, list, item, null, idx, -1);
304303
}
305304
}
306305
else
307-
ret = new ActionData(TheAction.Add, item, null, list.Count, -1, list);
306+
ret = new ActionData(TheAction.Add, list, item, null, list.Count, -1);
308307
return ret;
309308
}
310309

@@ -339,7 +338,7 @@ ActionData SortedMove(ActionData data)
339338
data.OldItem.CopyFrom(data.Item);
340339
var pos = FindNewPositionForItem(data.OldPosition, data.Position < 0, data.List, comparer, sortedIndexCache);
341340
// the old item is the one moving around
342-
return new ActionData(data.TheAction, data.OldItem, null, pos, data.OldPosition, data.List);
341+
return new ActionData(data, pos);
343342
}
344343

345344
ActionData SortedRemove(ActionData data)
@@ -879,55 +878,51 @@ struct ActionData
879878
readonly public List<T> List;
880879

881880
public ActionData(ActionData other, int index, int indexPivot)
881+
: this(other.TheAction, other.List,
882+
other.Item, other.OldItem,
883+
other.Position, other.OldPosition,
884+
index, indexPivot,
885+
other.IsIncluded)
882886
{
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;
892887
}
893888

894889
public ActionData(ActionData other, int position)
890+
: this(other.TheAction, other.List,
891+
other.Item, other.OldItem,
892+
position, other.OldPosition,
893+
other.Index, other.IndexPivot,
894+
other.IsIncluded)
895895
{
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;
905896
}
906897

907898
public ActionData(ActionData other, bool isIncluded)
899+
: this(other.TheAction, other.List,
900+
other.Item, other.OldItem,
901+
other.Position, other.OldPosition,
902+
other.Index, other.IndexPivot,
903+
isIncluded)
908904
{
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;
918905
}
919906

920-
public ActionData(TheAction action, T item, T oldItem, int position, int oldPosition, List<T> list)
907+
public ActionData(TheAction action, List<T> list, T item, T oldItem, int position, int oldPosition)
908+
: this(action, list,
909+
item, oldItem,
910+
position, oldPosition,
911+
-1, -1, false)
912+
{
913+
}
914+
915+
public ActionData(TheAction action, List<T> list, T item, T oldItem, int position, int oldPosition, int index, int indexPivot, bool isIncluded)
921916
{
922917
TheAction = action;
923918
Item = item;
924919
OldItem = oldItem;
925920
Position = position;
926921
OldPosition = oldPosition;
927922
List = list;
928-
Index = -1;
929-
IndexPivot = -1;
930-
IsIncluded = false;
923+
Index = index;
924+
IndexPivot = indexPivot;
925+
IsIncluded = isIncluded;
931926
}
932927
}
933928
}

0 commit comments

Comments
 (0)