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.
This commit is contained in:
Łukasz Domeradzki
2025-08-08 23:10:35 +02:00
parent 2387f2462e
commit c412a47139
2 changed files with 6 additions and 6 deletions

View File

@@ -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());
}

View File

@@ -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));
}