Skip to content

Commit 7bc3595

Browse files
committed
avoid Union() enumerator in player inventory tracking
1 parent db59d38 commit 7bc3595

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/SMAPI/Framework/StateTracking/PlayerTracker.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
4-
using System.Linq;
54
using StardewModdingAPI.Enums;
65
using StardewModdingAPI.Framework.StateTracking.Comparers;
76
using StardewModdingAPI.Framework.StateTracking.FieldWatchers;
@@ -112,12 +111,17 @@ public bool TryGetInventoryChanges([NotNullWhen(true)] out SnapshotItemListDiff?
112111
{
113112
HashSet<Item> added = new(new ObjectReferenceComparer<Item>());
114113
HashSet<Item> removed = new(new ObjectReferenceComparer<Item>());
115-
foreach (Item item in this.PreviousInventory.Keys.Union(this.CurrentInventory.Keys))
114+
115+
foreach (Item item in this.PreviousInventory.Keys)
116+
{
117+
if (!this.CurrentInventory.ContainsKey(item))
118+
removed.Add(item);
119+
}
120+
121+
foreach (Item item in this.CurrentInventory.Keys)
116122
{
117123
if (!this.PreviousInventory.ContainsKey(item))
118124
added.Add(item);
119-
else if (!this.CurrentInventory.ContainsKey(item))
120-
removed.Add(item);
121125
}
122126

123127
return SnapshotItemListDiff.TryGetChanges(added: added, removed: removed, stackSizes: this.PreviousInventory, out changes);

0 commit comments

Comments
 (0)