Skip to content

Commit 24ff951

Browse files
committed
Decided to expand the small buffer to avoid need to rent some of the fixed size 16 byte arrays
1 parent c97b4eb commit 24ff951

File tree

1 file changed

+12
-52
lines changed

1 file changed

+12
-52
lines changed

src/FirebirdSql.Data.FirebirdClient/Client/Managed/XdrReaderWriter.cs

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public XdrReaderWriter(IDataProvider dataProvider, Charset charset)
4141
_dataProvider = dataProvider;
4242
_charset = charset;
4343

44-
_smallBuffer = new byte[8];
44+
_smallBuffer = new byte[16];
4545
}
4646

4747
public XdrReaderWriter(IDataProvider dataProvider)
@@ -309,17 +309,9 @@ public async ValueTask<Guid> ReadGuidAsync(int sqlType, CancellationToken cancel
309309
return TypeDecoder.DecodeGuid(await ReadBufferAsync(cancellationToken).ConfigureAwait(false));
310310
}
311311
else
312-
{
313-
var rented = ArrayPool<byte>.Shared.Rent(16);
314-
try
315-
{
316-
await ReadBytesAsync(rented, 16, cancellationToken).ConfigureAwait(false);
317-
return TypeDecoder.DecodeGuid(rented);
318-
}
319-
finally
320-
{
321-
ArrayPool<byte>.Shared.Return(rented);
322-
}
312+
{
313+
await ReadBytesAsync(_smallBuffer, 16, cancellationToken).ConfigureAwait(false);
314+
return TypeDecoder.DecodeGuid(_smallBuffer);
323315
}
324316
}
325317

@@ -480,56 +472,24 @@ public async ValueTask<FbDecFloat> ReadDec16Async(CancellationToken cancellation
480472

481473
public FbDecFloat ReadDec34()
482474
{
483-
var rented = ArrayPool<byte>.Shared.Rent(16);
484-
try
485-
{
486-
ReadBytes(rented, 16);
487-
return TypeDecoder.DecodeDec34(rented);
488-
}
489-
finally
490-
{
491-
ArrayPool<byte>.Shared.Return(rented);
492-
}
475+
ReadBytes(_smallBuffer, 16);
476+
return TypeDecoder.DecodeDec34(_smallBuffer);
493477
}
494478
public async ValueTask<FbDecFloat> ReadDec34Async(CancellationToken cancellationToken = default)
495479
{
496-
var rented = ArrayPool<byte>.Shared.Rent(16);
497-
try
498-
{
499-
await ReadBytesAsync(rented, 16, cancellationToken).ConfigureAwait(false);
500-
return TypeDecoder.DecodeDec34(rented);
501-
}
502-
finally
503-
{
504-
ArrayPool<byte>.Shared.Return(rented);
505-
}
480+
await ReadBytesAsync(_smallBuffer, 16, cancellationToken).ConfigureAwait(false);
481+
return TypeDecoder.DecodeDec34(_smallBuffer);
506482
}
507483

508484
public BigInteger ReadInt128()
509485
{
510-
var rented = ArrayPool<byte>.Shared.Rent(16);
511-
try
512-
{
513-
ReadBytes(rented, 16);
514-
return TypeDecoder.DecodeInt128(rented);
515-
}
516-
finally
517-
{
518-
ArrayPool<byte>.Shared.Return(rented);
519-
}
486+
ReadBytes(_smallBuffer, 16);
487+
return TypeDecoder.DecodeInt128(_smallBuffer);
520488
}
521489
public async ValueTask<BigInteger> ReadInt128Async(CancellationToken cancellationToken = default)
522490
{
523-
var rented = ArrayPool<byte>.Shared.Rent(16);
524-
try
525-
{
526-
await ReadBytesAsync(rented, 16, cancellationToken).ConfigureAwait(false);
527-
return TypeDecoder.DecodeInt128(rented);
528-
}
529-
finally
530-
{
531-
ArrayPool<byte>.Shared.Return(rented);
532-
}
491+
await ReadBytesAsync(_smallBuffer, 16, cancellationToken).ConfigureAwait(false);
492+
return TypeDecoder.DecodeInt128(_smallBuffer);
533493
}
534494

535495
public IscException ReadStatusVector()

0 commit comments

Comments
 (0)