From c412a47139b50abccd7cf050526b422d0cbb3d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Fri, 8 Aug 2025 23:10:35 +0200 Subject: [PATCH] Optimize memory allocations when dealing with Steam items This removes totally unnecessary allocation of asset and description when we already have it in the response and merely initializing to correct reference. --- ArchiSteamFarm/Steam/Data/Asset.cs | 6 +++--- ArchiSteamFarm/Steam/Data/InventoryDescription.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ArchiSteamFarm/Steam/Data/Asset.cs b/ArchiSteamFarm/Steam/Data/Asset.cs index 5a3510de2..4b36d0e8e 100644 --- a/ArchiSteamFarm/Steam/Data/Asset.cs +++ b/ArchiSteamFarm/Steam/Data/Asset.cs @@ -37,7 +37,7 @@ public sealed class Asset { public const ulong SteamPointsShopInstanceID = 3865004543; [JsonIgnore] - public CEcon_Asset Body { get; } = new(); + public CEcon_Asset Body { get; } [JsonIgnore] public bool IsSteamPointsShopItem => !Tradable && (InstanceID == SteamPointsShopInstanceID); @@ -123,7 +123,7 @@ public sealed class Asset { Description = description; } - public Asset(uint appID, ulong contextID, ulong classID, uint amount, InventoryDescription? description = null, ulong assetID = 0, ulong instanceID = 0) { + public Asset(uint appID, ulong contextID, ulong classID, uint amount, InventoryDescription? description = null, ulong assetID = 0, ulong instanceID = 0) : this() { ArgumentOutOfRangeException.ThrowIfZero(appID); ArgumentOutOfRangeException.ThrowIfZero(contextID); ArgumentOutOfRangeException.ThrowIfZero(classID); @@ -140,7 +140,7 @@ public sealed class Asset { } [JsonConstructor] - private Asset() { } + private Asset() => Body = new CEcon_Asset(); public Asset DeepClone() => new(Serializer.DeepClone(Body), Description?.DeepClone()); } diff --git a/ArchiSteamFarm/Steam/Data/InventoryDescription.cs b/ArchiSteamFarm/Steam/Data/InventoryDescription.cs index 1d05a75f2..d7b6415f1 100644 --- a/ArchiSteamFarm/Steam/Data/InventoryDescription.cs +++ b/ArchiSteamFarm/Steam/Data/InventoryDescription.cs @@ -38,7 +38,7 @@ namespace ArchiSteamFarm.Steam.Data; [PublicAPI] public sealed class InventoryDescription { [JsonIgnore] - public CEconItem_Description Body { get; } = new(); + public CEconItem_Description Body { get; } [JsonInclude] [JsonPropertyName("appid")] @@ -531,7 +531,7 @@ public sealed class InventoryDescription { Body = description; } - public InventoryDescription(uint appID, ulong classID, ulong instanceID = 0, bool marketable = false, bool tradable = false, uint realAppID = 0, EAssetType type = EAssetType.Unknown, EAssetRarity rarity = EAssetRarity.Unknown) { + public InventoryDescription(uint appID, ulong classID, ulong instanceID = 0, bool marketable = false, bool tradable = false, uint realAppID = 0, EAssetType type = EAssetType.Unknown, EAssetRarity rarity = EAssetRarity.Unknown) : this() { ArgumentOutOfRangeException.ThrowIfZero(appID); ArgumentOutOfRangeException.ThrowIfZero(classID); @@ -555,7 +555,7 @@ public sealed class InventoryDescription { } [JsonConstructor] - private InventoryDescription() { } + private InventoryDescription() => Body = new CEconItem_Description(); public InventoryDescription DeepClone() => new(Serializer.DeepClone(Body)); }