Merge pull request #1124 from JonHanna/lazier_largeByteBuffer

Don't assign _largeByteBuffer until clear it will be used.
This commit is contained in:
James Newton-King
2017-01-01 15:06:06 +13:00
committed by GitHub
+3 -2
View File
@@ -209,13 +209,14 @@ namespace Newtonsoft.Json.Bson
public void WriteUtf8Bytes(string s, int byteCount) public void WriteUtf8Bytes(string s, int byteCount)
{ {
if (s != null) if (s != null)
{
if (byteCount <= 256)
{ {
if (_largeByteBuffer == null) if (_largeByteBuffer == null)
{ {
_largeByteBuffer = new byte[256]; _largeByteBuffer = new byte[256];
} }
if (byteCount <= 256)
{
Encoding.GetBytes(s, 0, s.Length, _largeByteBuffer, 0); Encoding.GetBytes(s, 0, s.Length, _largeByteBuffer, 0);
_writer.Write(_largeByteBuffer, 0, byteCount); _writer.Write(_largeByteBuffer, 0, byteCount);
} }