mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
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:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user