Procházet zdrojové kódy

Performance refactoring.

release/3.x.x
Christian Kratky před 5 roky
rodič
revize
985c3084a8
1 změnil soubory, kde provedl 8 přidání a 16 odebrání
  1. +8
    -16
      Source/MQTTnet/Formatter/MqttPacketBodyReader.cs

+ 8
- 16
Source/MQTTnet/Formatter/MqttPacketBodyReader.cs Zobrazit soubor

@@ -22,10 +22,7 @@ namespace MQTTnet.Formatter
_length = length;
}

public int Offset
{
get => _offset;
}
public int Offset => _offset;

public int Length => _length - _offset;

@@ -36,22 +33,13 @@ namespace MQTTnet.Formatter
_offset = _initialOffset + position;
}

public ArraySegment<byte> Read(int length)
{
ValidateReceiveBuffer(length);

var buffer = new ArraySegment<byte>(_buffer, (int)_offset, (int)length);
_offset += length;
return buffer;
}

public byte ReadByte()
{
ValidateReceiveBuffer(1);

return _buffer[_offset++];
}
public bool ReadBoolean()
{
ValidateReceiveBuffer(1);
@@ -73,7 +61,11 @@ namespace MQTTnet.Formatter

public byte[] ReadRemainingData()
{
return new ArraySegment<byte>(_buffer, (int)_offset, (int)(_length - _offset)).ToArray();
var bufferLength = _length - _offset;
var buffer = new byte[bufferLength];
Array.Copy(_buffer, _offset, buffer, 0, bufferLength);

return buffer;
}

public ushort ReadTwoByteInteger()
@@ -131,7 +123,7 @@ namespace MQTTnet.Formatter

ValidateReceiveBuffer(length);

var result = new ArraySegment<byte>(_buffer, (int)_offset, length);
var result = new ArraySegment<byte>(_buffer, _offset, length);
_offset += length;

return result;


Načítá se…
Zrušit
Uložit