GW2.NET
GW2.NET copied to clipboard
Performance: merge json array with existing list
[Moved from Codeplex: https://gw2dotnet.codeplex.com/workitem/1345]
Inspired by: https://forum-en.guildwars2.com/forum/community/api/Minor-issue-with-X-Result-Total/first#post5103839
The API returns the X-Result-Count of objects with every bulk-expanded response. We should use that value to specify the initial capacity of collection types.
collection.Capacity == X-Result-Count
Unfortunately, Json.NET does not support specifying a capacity for deserialized lists.
Fortunately, Json.NET supports merging json values with an existing object.
TODO (up for grabs) update json collection converters to first create a new list with a specified capacity, then let Json.NET populate the list with objects
// Pseudo code
var list = new List<TDataContract>(X-Result-Count);
JsonConvert.PopulateObject(list, httpResponseContent);