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.
This commit is contained in:
JustArchi
2016-07-08 06:45:10 +02:00
parent 412028eff7
commit 09b2b29ff4
3 changed files with 0 additions and 6 deletions

View File

@@ -268,7 +268,6 @@ namespace ArchiSteamFarm {
if (acceptedType != Steam.ConfirmationDetails.EType.Unknown) { if (acceptedType != Steam.ConfirmationDetails.EType.Unknown) {
if (confirmations.RemoveWhere(confirmation => (confirmation.Type != acceptedType) && (confirmation.Type != Steam.ConfirmationDetails.EType.Other)) > 0) { if (confirmations.RemoveWhere(confirmation => (confirmation.Type != acceptedType) && (confirmation.Type != Steam.ConfirmationDetails.EType.Other)) > 0) {
confirmations.TrimExcess();
if (confirmations.Count == 0) { if (confirmations.Count == 0) {
return; return;
} }
@@ -288,7 +287,6 @@ namespace ArchiSteamFarm {
if (ignoredConfirmationIDs.Count > 0) { if (ignoredConfirmationIDs.Count > 0) {
if (confirmations.RemoveWhere(confirmation => ignoredConfirmationIDs.Contains(confirmation.ID)) > 0) { if (confirmations.RemoveWhere(confirmation => ignoredConfirmationIDs.Contains(confirmation.ID)) > 0) {
confirmations.TrimExcess();
if (confirmations.Count == 0) { if (confirmations.Count == 0) {
return; return;
} }
@@ -717,7 +715,6 @@ namespace ArchiSteamFarm {
// Remove from our pending inventory all items that are not steam cards and boosters // 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.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) { if (inventory.Count == 0) {
return "Nothing to send, inventory seems empty!"; return "Nothing to send, inventory seems empty!";

View File

@@ -128,7 +128,6 @@ namespace ArchiSteamFarm {
uint appID = gamesToFarmSolo.First(); uint appID = gamesToFarmSolo.First();
if (await FarmSolo(appID).ConfigureAwait(false)) { if (await FarmSolo(appID).ConfigureAwait(false)) {
gamesToFarmSolo.Remove(appID); gamesToFarmSolo.Remove(appID);
gamesToFarmSolo.TrimExcess();
} else { } else {
NowFarming = false; NowFarming = false;
return; return;

View File

@@ -101,7 +101,6 @@ namespace ArchiSteamFarm {
} }
if (tradeOffers.RemoveWhere(tradeoffer => IgnoredTrades.Contains(tradeoffer.TradeOfferID)) > 0) { if (tradeOffers.RemoveWhere(tradeoffer => IgnoredTrades.Contains(tradeoffer.TradeOfferID)) > 0) {
tradeOffers.TrimExcess();
if (tradeOffers.Count == 0) { if (tradeOffers.Count == 0) {
return; return;
} }
@@ -211,7 +210,6 @@ namespace ArchiSteamFarm {
// Now remove from our inventory all items we're NOT interested in // Now remove from our inventory all items we're NOT interested in
inventory.RemoveWhere(item => !appIDs.Contains(item.RealAppID)); 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 for some reason Valve is talking crap and we can't find mentioned items, assume OK
if (inventory.Count == 0) { if (inventory.Count == 0) {