Skip to content

Commit a6f84f2

Browse files
authored
CSHARP-5531: Reduce memory allocations in BsonStreamAdapter.WriteDouble and WriteInt64 (#1670)
1 parent 081e408 commit a6f84f2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/MongoDB.Bson/IO/BsonStreamAdapter.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,8 @@ public override void WriteDecimal128(Decimal128 value)
495495
public override void WriteDouble(double value)
496496
{
497497
ThrowIfDisposed();
498-
var bytes = new byte[8];
499-
BinaryPrimitivesCompat.WriteDoubleLittleEndian(bytes, value);
500-
_stream.Write(bytes, 0, 8);
498+
BinaryPrimitivesCompat.WriteDoubleLittleEndian(_temp, value);
499+
_stream.Write(_temp, 0, 8);
501500
}
502501

503502
/// <inheritdoc/>
@@ -515,9 +514,8 @@ public override void WriteInt32(int value)
515514
public override void WriteInt64(long value)
516515
{
517516
ThrowIfDisposed();
518-
var bytes = new byte[8];
519-
BinaryPrimitives.WriteInt64LittleEndian(bytes, value);
520-
_stream.Write(bytes, 0, 8);
517+
BinaryPrimitives.WriteInt64LittleEndian(_temp, value);
518+
_stream.Write(_temp, 0, 8);
521519
}
522520

523521
/// <inheritdoc/>

0 commit comments

Comments
 (0)