Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Mar 14, 2016
2 parents 8110307 + 5ddbc50 commit 3107699
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
30 changes: 16 additions & 14 deletions Src/Newtonsoft.Json.Tests/DemoTests.cs
Expand Up @@ -609,23 +609,25 @@ public void ArrayPooling()

Assert.AreEqual(4, value.Count);
}
#endif
}

public class JsonArrayPool : IArrayPool<char>
{
public static readonly JsonArrayPool Instance = new JsonArrayPool();
#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50)
public class JsonArrayPool : IArrayPool<char>
{
public static readonly JsonArrayPool Instance = new JsonArrayPool();

public char[] Rent(int minimumLength)
{
// use System.Buffers shared pool
return ArrayPool<char>.Shared.Rent(minimumLength);
}
public char[] Rent(int minimumLength)
{
// use System.Buffers shared pool
return ArrayPool<char>.Shared.Rent(minimumLength);
}

public void Return(char[] array)
{
// use System.Buffers shared pool
ArrayPool<char>.Shared.Return(array);
}
public void Return(char[] array)
{
// use System.Buffers shared pool
ArrayPool<char>.Shared.Return(array);
}
#endif
}
#endif
}
28 changes: 28 additions & 0 deletions Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs
Expand Up @@ -49,6 +49,7 @@
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;

namespace Newtonsoft.Json.Tests
Expand Down Expand Up @@ -136,6 +137,33 @@ public void BufferTest_WithError()
Assert.AreEqual(1, arrayPool.FreeArrays.Count);
}

#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50)
[Test]
public void BufferErroringWithInvalidSize()
{
JObject o = new JObject
{
{"BodyHtml", "<h3>Title!</h3>" + Environment.NewLine + new string(' ', 100) + "<p>Content!</p>"}
};

JsonArrayPool arrayPool = new JsonArrayPool();

StringWriter sw = new StringWriter();
using (JsonTextWriter writer = new JsonTextWriter(sw))
{
writer.ArrayPool = arrayPool;

o.WriteTo(writer);
}

string result = o.ToString();

Assert.AreEqual(@"{
""BodyHtml"": ""<h3>Title!</h3>\r\n <p>Content!</p>""
}", result);
}
#endif

[Test]
public void NewLine()
{
Expand Down
Expand Up @@ -3,7 +3,7 @@
"Autofac": "4.0.0-beta7-130",
"FSharp.Core": "4.0.0.1",
"NUnit": "2.6.2",
"System.Buffers": "4.0.0-rc2-23623",
"System.Buffers": "4.0.0-rc2-23826",
"System.Collections.Immutable": "1.1.37"
},
"frameworks": {
Expand Down
2 changes: 1 addition & 1 deletion Src/Newtonsoft.Json.Tests/project.json
Expand Up @@ -33,7 +33,7 @@
"FSharp.Core": "4.0.0.1",
"NUnit": "2.6.4",
"System.Collections.Immutable": "1.1.37",
"System.Buffers": "4.0.0-rc2-23623"
"System.Buffers": "4.0.0-rc2-23826"
}
},
"net40": {
Expand Down
4 changes: 2 additions & 2 deletions Src/Newtonsoft.Json/MemberSerialization.cs
Expand Up @@ -42,7 +42,7 @@ public enum MemberSerialization
OptOut = 0,

/// <summary>
/// Only members must be marked with <see cref="JsonPropertyAttribute"/> or <see cref="DataMemberAttribute"/> are serialized.
/// Only members marked with <see cref="JsonPropertyAttribute"/> or <see cref="DataMemberAttribute"/> are serialized.
/// This member serialization mode can also be set by marking the class with <see cref="DataContractAttribute"/>.
/// </summary>
OptIn = 1,
Expand All @@ -55,4 +55,4 @@ public enum MemberSerialization
Fields = 2
#pragma warning restore 1584,1711,1572,1581,1580,1574
}
}
}
2 changes: 1 addition & 1 deletion Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs
Expand Up @@ -286,7 +286,7 @@ public static bool ShouldEscapeJavaScriptString(string s, bool[] charEscapeFlags

if (writeBuffer == null || writeBuffer.Length < length)
{
writeBuffer = new char[length];
writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer);
}

s.CopyTo(lastWritePosition, writeBuffer, 0, length);
Expand Down

0 comments on commit 3107699

Please sign in to comment.