From 09b2b29ff4f0caee36d3085c3307951ff2c93218 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 8 Jul 2016 06:45:10 +0200 Subject: [PATCH] Avoid excessive TrimExcess() It's really good for keeping memory low, but due to limited lifespan of those objects and the fact that we should focus on performance and not memory, it's better to avoid extra overhead and let GC do it's job, by dropping references to those objects ASAP TrimExcess() is still being used for global objects, as those have longer (possibly infinite) lifespan and can benefit from that. --- ArchiSteamFarm/Bot.cs | 3 --- ArchiSteamFarm/CardsFarmer.cs | 1 - ArchiSteamFarm/Trading.cs | 2 -- 3 files changed, 6 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index d95d35dc1..44c5e5c68 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -268,7 +268,6 @@ namespace ArchiSteamFarm { if (acceptedType != Steam.ConfirmationDetails.EType.Unknown) { if (confirmations.RemoveWhere(confirmation => (confirmation.Type != acceptedType) && (confirmation.Type != Steam.ConfirmationDetails.EType.Other)) > 0) { - confirmations.TrimExcess(); if (confirmations.Count == 0) { return; } @@ -288,7 +287,6 @@ namespace ArchiSteamFarm { if (ignoredConfirmationIDs.Count > 0) { if (confirmations.RemoveWhere(confirmation => ignoredConfirmationIDs.Contains(confirmation.ID)) > 0) { - confirmations.TrimExcess(); if (confirmations.Count == 0) { return; } @@ -717,7 +715,6 @@ namespace ArchiSteamFarm { // Remove from our pending inventory all items that are not steam cards and boosters inventory.RemoveWhere(item => (item.Type != Steam.Item.EType.TradingCard) && (item.Type != Steam.Item.EType.FoilTradingCard) && (item.Type != Steam.Item.EType.BoosterPack)); - inventory.TrimExcess(); if (inventory.Count == 0) { return "Nothing to send, inventory seems empty!"; diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 2a67b7c45..815582b31 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -128,7 +128,6 @@ namespace ArchiSteamFarm { uint appID = gamesToFarmSolo.First(); if (await FarmSolo(appID).ConfigureAwait(false)) { gamesToFarmSolo.Remove(appID); - gamesToFarmSolo.TrimExcess(); } else { NowFarming = false; return; diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index f12f251cc..69e23d353 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -101,7 +101,6 @@ namespace ArchiSteamFarm { } if (tradeOffers.RemoveWhere(tradeoffer => IgnoredTrades.Contains(tradeoffer.TradeOfferID)) > 0) { - tradeOffers.TrimExcess(); if (tradeOffers.Count == 0) { return; } @@ -211,7 +210,6 @@ namespace ArchiSteamFarm { // Now remove from our inventory all items we're NOT interested in inventory.RemoveWhere(item => !appIDs.Contains(item.RealAppID)); - inventory.TrimExcess(); // If for some reason Valve is talking crap and we can't find mentioned items, assume OK if (inventory.Count == 0) {