diff --git a/Src/Newtonsoft.Json.Tests/DemoTests.cs b/Src/Newtonsoft.Json.Tests/DemoTests.cs index 39bbffbd..d0b6cd57 100644 --- a/Src/Newtonsoft.Json.Tests/DemoTests.cs +++ b/Src/Newtonsoft.Json.Tests/DemoTests.cs @@ -24,7 +24,11 @@ #endregion using System; +#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50) +using System.Buffers; +#endif using System.Collections.Generic; +using System.IO; using System.Text; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; @@ -588,5 +592,40 @@ namespace Newtonsoft.Json.Tests ] }", json); } + +#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50) + [Test] + public void ArrayPooling() + { + IList value; + + JsonSerializer serializer = new JsonSerializer(); + using (JsonTextReader reader = new JsonTextReader(new StringReader(@"[1,2,3,4]"))) + { + reader.ArrayPool = JsonArrayPool.Instance; + + value = serializer.Deserialize>(reader); + } + + Assert.AreEqual(4, value.Count); + } + + public class JsonArrayPool : IArrayPool + { + public static readonly JsonArrayPool Instance = new JsonArrayPool(); + + public char[] Rent(int minimumLength) + { + // use System.Buffers shared pool + return ArrayPool.Shared.Rent(minimumLength); + } + + public void Return(char[] array) + { + // use System.Buffers shared pool + ArrayPool.Shared.Return(array); + } + } +#endif } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index 55c096fa..bcee95be 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -856,21 +856,6 @@ If attributes are not mentioned, default values are used in each case. } } - public class JsonArrayPool : IArrayPool - { - public static readonly JsonArrayPool Instance = new JsonArrayPool(); - - public char[] Rent(int minimumLength) - { - return ArrayPool.Shared.Rent(minimumLength); - } - - public void Return(char[] array) - { - ArrayPool.Shared.Return(array); - } - } - public TestClass DeserializeJsonNetManual(string json) { TestClass c = new TestClass();