Skip to content

Commit f9995c4

Browse files
committed
Less buffers.
1 parent b147f06 commit f9995c4

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsDatabase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,25 +369,25 @@ public virtual void ConnectionRequest(out int auxHandle, out string ipAddress, o
369369
auxHandle = XdrStream.ReadInt32();
370370

371371
var garbage1 = new byte[8];
372-
XdrStream.ReadBytes(garbage1);
372+
XdrStream.ReadBytes(garbage1, 8);
373373

374374
var respLen = XdrStream.ReadInt32();
375375
respLen += respLen % 4;
376376

377377
var sin_family = new byte[2];
378-
XdrStream.ReadBytes(sin_family);
378+
XdrStream.ReadBytes(sin_family, 2);
379379
respLen -= 2;
380380

381381
var sin_port = new byte[2];
382-
XdrStream.ReadBytes(sin_port);
382+
XdrStream.ReadBytes(sin_port, 2);
383383
portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(sin_port, 0));
384384
respLen -= 2;
385385

386386
// * The address returned by the server may be incorrect if it is behind a NAT box
387387
// * so we must use the address that was used to connect the main socket, not the
388388
// * address reported by the server.
389389
var sin_addr = new byte[4];
390-
XdrStream.ReadBytes(sin_addr);
390+
XdrStream.ReadBytes(sin_addr, 4);
391391
//ipAddress = string.Format(
392392
// CultureInfo.InvariantCulture,
393393
// "{0}.{1}.{2}.{3}",
@@ -396,7 +396,7 @@ public virtual void ConnectionRequest(out int auxHandle, out string ipAddress, o
396396
respLen -= 4;
397397

398398
var garbage2 = new byte[respLen];
399-
XdrStream.ReadBytes(garbage2);
399+
XdrStream.ReadBytes(garbage2, respLen);
400400

401401
XdrStream.ReadStatusVector();
402402
}

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsEventManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task WaitForEventsAsync(RemoteEvent remoteEvent)
5757
var dbHandle = _database.XdrStream.ReadInt32();
5858
var buffer = _database.XdrStream.ReadBuffer();
5959
var ast = new byte[8];
60-
_database.XdrStream.ReadBytes(ast);
60+
_database.XdrStream.ReadBytes(ast, 8);
6161
var eventId = _database.XdrStream.ReadInt32();
6262

6363
remoteEvent.EventCounts(buffer);

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/XdrStream.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal class XdrStream : Stream
4848
private long _position;
4949
private List<byte> _outputBuffer;
5050
private Queue<byte> _inputBuffer;
51+
private byte[] _smallBuffer;
5152
private Ionic.Zlib.ZlibCodec _deflate;
5253
private Ionic.Zlib.ZlibCodec _inflate;
5354
private byte[] _compressionBuffer;
@@ -121,6 +122,7 @@ public XdrStream(Stream innerStream, Charset charset, bool compression, bool own
121122
_position = 0;
122123
_outputBuffer = new List<byte>(PreferredBufferSize);
123124
_inputBuffer = new Queue<byte>(PreferredBufferSize);
125+
_smallBuffer = new byte[8];
124126
if (_compression)
125127
{
126128
_deflate = new Ionic.Zlib.ZlibCodec(Ionic.Zlib.CompressionMode.Compress);
@@ -334,9 +336,8 @@ private void ResetOperation()
334336

335337
#region XDR Read Methods
336338

337-
public byte[] ReadBytes(byte[] buffer)
339+
public byte[] ReadBytes(byte[] buffer, int count)
338340
{
339-
var count = buffer.Length;
340341
if (count > 0)
341342
{
342343
var toRead = count;
@@ -353,9 +354,8 @@ public byte[] ReadBytes(byte[] buffer)
353354
}
354355
return buffer;
355356
}
356-
public async Task<byte[]> ReadBytesAsync(byte[] buffer)
357+
public async Task<byte[]> ReadBytesAsync(byte[] buffer, int count)
357358
{
358-
var count = buffer.Length;
359359
if (count > 0)
360360
{
361361
var toRead = count;
@@ -376,7 +376,7 @@ public async Task<byte[]> ReadBytesAsync(byte[] buffer)
376376
public byte[] ReadOpaque(int length)
377377
{
378378
var buffer = new byte[length];
379-
ReadBytes(buffer);
379+
ReadBytes(buffer, length);
380380
var padLength = ((4 - length) & 3);
381381
if (padLength > 0)
382382
{
@@ -417,26 +417,24 @@ public short ReadInt16()
417417
return Convert.ToInt16(ReadInt32());
418418
}
419419

420-
private byte[] int32Buffer = new byte[4];
421420
public int ReadInt32()
422421
{
423-
Array.Clear(int32Buffer, 0, 4);
424-
ReadBytes(int32Buffer);
425-
return IPAddress.HostToNetworkOrder(BitConverter.ToInt32(int32Buffer, 0));
422+
Array.Clear(_smallBuffer, 0, 4);
423+
ReadBytes(_smallBuffer, 4);
424+
return IPAddress.HostToNetworkOrder(BitConverter.ToInt32(_smallBuffer, 0));
426425
}
427426
public async Task<int> ReadInt32Async()
428427
{
429-
Array.Clear(int32Buffer, 0, 4);
430-
await ReadBytesAsync(int32Buffer).ConfigureAwait(false);
431-
return IPAddress.HostToNetworkOrder(BitConverter.ToInt32(int32Buffer, 0));
428+
Array.Clear(_smallBuffer, 0, 4);
429+
await ReadBytesAsync(_smallBuffer, 4).ConfigureAwait(false);
430+
return IPAddress.HostToNetworkOrder(BitConverter.ToInt32(_smallBuffer, 0));
432431
}
433432

434-
private byte[] int64Buffer = new byte[8];
435433
public long ReadInt64()
436434
{
437-
Array.Clear(int64Buffer, 0, 8);
438-
ReadBytes(int64Buffer);
439-
return IPAddress.HostToNetworkOrder(BitConverter.ToInt64(int64Buffer, 0));
435+
Array.Clear(_smallBuffer, 0, 8);
436+
ReadBytes(_smallBuffer, 8);
437+
return IPAddress.HostToNetworkOrder(BitConverter.ToInt64(_smallBuffer, 0));
440438
}
441439

442440
public Guid ReadGuid()

0 commit comments

Comments
 (0)