From 626452834fed7f15e20f2ecc0d4103be69621193 Mon Sep 17 00:00:00 2001 From: James Finlay Date: Mon, 7 Mar 2016 21:47:52 -0800 Subject: 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. --- StardewModdingAPI/Inheritance/SGame.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'StardewModdingAPI/Inheritance') 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) -- cgit