From b0ef7309b818f8a55203b5aa31948006187f193d Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 6 Mar 2020 00:06:39 +0100 Subject: [PATCH] More misc optimizations --- ArchiSteamFarm/ArchiWebHandler.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index a8c407a7d..35247a49e 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -1716,13 +1716,17 @@ namespace ArchiSteamFarm { const string request = "/gifts"; HtmlDocument response = await UrlGetToHtmlDocumentWithSession(SteamStoreURL, request).ConfigureAwait(false); - HtmlNodeCollection htmlNodes = response?.DocumentNode.SelectNodes("//div[@class='pending_gift']/div[starts-with(@id, 'pending_gift_')][count(div[@class='pending_giftcard_leftcol']) > 0]/@id"); - - if (htmlNodes == null) { + if (response == null) { return null; } - HashSet results = new HashSet(); + HtmlNodeCollection htmlNodes = response.DocumentNode.SelectNodes("//div[@class='pending_gift']/div[starts-with(@id, 'pending_gift_')][count(div[@class='pending_giftcard_leftcol']) > 0]/@id"); + + if (htmlNodes == null) { + return new HashSet(0); + } + + HashSet results = new HashSet(htmlNodes.Count); foreach (string giftCardIDText in htmlNodes.Select(node => node.GetAttributeValue("id", null))) { if (string.IsNullOrEmpty(giftCardIDText)) { @@ -1766,13 +1770,13 @@ namespace ArchiSteamFarm { HtmlNodeCollection htmlNodes = htmlDocument.DocumentNode.SelectNodes("(//table[@class='accountTable'])[2]//a/@data-miniprofile"); - HashSet result = new HashSet(); - if (htmlNodes == null) { // OK, no authorized steamIDs - return result; + return new HashSet(0); } + HashSet result = new HashSet(htmlNodes.Count); + foreach (string miniProfile in htmlNodes.Select(htmlNode => htmlNode.GetAttributeValue("data-miniprofile", null))) { if (string.IsNullOrEmpty(miniProfile)) { Bot.ArchiLogger.LogNullError(nameof(miniProfile));