Improve Json perf by using JObject.Load.

This commit is contained in:
Livar Cunha 2017-05-15 16:05:35 -07:00
parent e157c4bd09
commit 439c4e6173
2 changed files with 16 additions and 8 deletions

View file

@ -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
{
@ -32,8 +33,10 @@ namespace Microsoft.DotNet.Cli.Utils
}
private JObject OpenRuntimeConfig(string runtimeConfigPath)
{
return JObject.Parse(File.ReadAllText(runtimeConfigPath));
{
var reader = new JsonTextReader(new StringReader(File.ReadAllText(runtimeConfigPath)));
return JObject.Load(reader);
}
private RuntimeConfigFramework ParseFramework(JObject runtimeConfigRoot)

View file

@ -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;
@ -67,11 +69,14 @@ namespace Microsoft.DotNet.Cli
yield break;
}
var json = JObject.Parse(result);
foreach (var id in json["data"])
using (var reader = new JsonTextReader(new StringReader(result)))
{
yield return id["id"].Value<string>();
var json = JObject.Load(reader);
foreach (var id in json["data"])
{
yield return id["id"].Value<string>();
}
}
}
}