Merge pull request #6602 from livarcocc/json_perf_improvements
Improve Json perf by using JObject.Load.
This commit is contained in:
commit
68246a46fa
2 changed files with 27 additions and 14 deletions
|
@ -1,8 +1,9 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
@ -12,12 +13,16 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
public RuntimeConfigFramework Framework { get; }
|
||||
|
||||
public RuntimeConfig(string runtimeConfigPath)
|
||||
{
|
||||
var runtimeConfigJson = OpenRuntimeConfig(runtimeConfigPath);
|
||||
|
||||
Framework = ParseFramework(runtimeConfigJson);
|
||||
|
||||
IsPortable = Framework != null;
|
||||
{
|
||||
JObject runtimeConfigJson;
|
||||
using (var streamReader = new StreamReader(new FileStream(runtimeConfigPath, FileMode.Open)))
|
||||
{
|
||||
runtimeConfigJson = OpenRuntimeConfig(streamReader);
|
||||
}
|
||||
|
||||
Framework = ParseFramework(runtimeConfigJson);
|
||||
|
||||
IsPortable = Framework != null;
|
||||
}
|
||||
|
||||
public static bool IsApplicationPortable(string entryAssemblyPath)
|
||||
|
@ -31,9 +36,11 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
return false;
|
||||
}
|
||||
|
||||
private JObject OpenRuntimeConfig(string runtimeConfigPath)
|
||||
{
|
||||
return JObject.Parse(File.ReadAllText(runtimeConfigPath));
|
||||
private JObject OpenRuntimeConfig(StreamReader streamReader)
|
||||
{
|
||||
var reader = new JsonTextReader(streamReader);
|
||||
|
||||
return JObject.Load(reader);
|
||||
}
|
||||
|
||||
private RuntimeConfigFramework ParseFramework(JObject runtimeConfigRoot)
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings;
|
||||
|
||||
|
@ -52,7 +54,7 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
string result;
|
||||
Stream result;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -60,14 +62,18 @@ namespace Microsoft.DotNet.Cli
|
|||
var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token)
|
||||
.Result;
|
||||
|
||||
result = response.Content.ReadAsStringAsync().Result;
|
||||
result = response.Content.ReadAsStreamAsync().Result;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var json = JObject.Parse(result);
|
||||
JObject json;
|
||||
using (var reader = new JsonTextReader(new StreamReader(result)))
|
||||
{
|
||||
json = JObject.Load(reader);
|
||||
}
|
||||
|
||||
foreach (var id in json["data"])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue