GW2.NET icon indicating copy to clipboard operation
GW2.NET copied to clipboard

Performance: merge json array with existing list

Open SamHurne opened this issue 8 years ago • 0 comments

[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);

SamHurne avatar Sep 19 '15 15:09 SamHurne