Don't assign _largeByteBuffer until clear it will be used.

BsonBinaryWriter._largeByteBuffer is lazily-allocated, but a path
following the allocation doesn't use it. Move the allocation into the
path that makes use of it, to avoid the null-check and potentially the
allocation.
This commit is contained in:
Jon Hanna
2016-12-31 14:35:55 +00:00
parent 322252a989
commit ecd265dad9
+5 -4
View File
@@ -210,12 +210,13 @@ namespace Newtonsoft.Json.Bson
{
if (s != null)
{
if (_largeByteBuffer == null)
{
_largeByteBuffer = new byte[256];
}
if (byteCount <= 256)
{
if (_largeByteBuffer == null)
{
_largeByteBuffer = new byte[256];
}
Encoding.GetBytes(s, 0, s.Length, _largeByteBuffer, 0);
_writer.Write(_largeByteBuffer, 0, byteCount);
}