diff options
author | James Finlay <jtfinlay@ualberta.ca> | 2016-03-07 21:47:52 -0800 |
---|---|---|
committer | James Finlay <jtfinlay@ualberta.ca> | 2016-03-07 21:47:52 -0800 |
commit | 626452834fed7f15e20f2ecc0d4103be69621193 (patch) | |
tree | 2e7d130a11429bf98d1b5b5042e64d1912b43aee | |
parent | 38f59b079ec9f24c574d2681a41555038b291b03 (diff) | |
download | SMAPI-626452834fed7f15e20f2ecc0d4103be69621193.tar.gz SMAPI-626452834fed7f15e20f2ecc0d4103be69621193.tar.bz2 SMAPI-626452834fed7f15e20f2ecc0d4103be69621193.zip |
Perf improvements
- The original '+=' of the GetHash method was taking ~10% of CPU usage for the game. This should improve performance considerably.
- The next largest CPU usage we care about is the 'GetHash' method that gets called very often. Pulling the objects.GetHash() out will reduce hits on the method.
-rw-r--r-- | StardewModdingAPI/Extensions.cs | 6 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/SGame.cs | 7 |
2 files changed, 7 insertions, 6 deletions
diff --git a/StardewModdingAPI/Extensions.cs b/StardewModdingAPI/Extensions.cs index 7e849f12..c504f470 100644 --- a/StardewModdingAPI/Extensions.cs +++ b/StardewModdingAPI/Extensions.cs @@ -53,12 +53,12 @@ namespace StardewModdingAPI public static int GetHash(this IEnumerable enumerable) { - string s = string.Empty; + int hash = 0; foreach (var v in enumerable) { - s += v.GetHashCode().ToString(); + hash ^= v.GetHashCode(); } - return s.GetHashCode(); + return hash; } } }
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index cccdff23..735cd58a 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -465,12 +465,13 @@ namespace StardewModdingAPI.Inheritance {
Events.PlayerEvents.InvokeInventoryChanged(player.items, changedItems);
PreviousItems = player.items.Where(n => n != null).ToDictionary(n => n, n => n.Stack);
- }
+ }
- if(currentLocation != null && PreviousLocationObjects != currentLocation.objects.GetHash())
+ var objectHash = currentLocation?.objects?.GetHash();
+ if(objectHash != null && PreviousLocationObjects != objectHash)
{
Events.LocationEvents.InvokeOnNewLocationObject(currentLocation.objects);
- PreviousLocationObjects = currentLocation.objects.GetHash();
+ PreviousLocationObjects = objectHash ?? -1;
}
if (timeOfDay != PreviousTimeOfDay)
|