Преглед на файлове

Performance refactoring.

release/3.x.x
Christian Kratky преди 5 години
родител
ревизия
985c3084a8
променени са 1 файла, в които са добавени 8 реда и са изтрити 16 реда
  1. +8
    -16
      Source/MQTTnet/Formatter/MqttPacketBodyReader.cs

+ 8
- 16
Source/MQTTnet/Formatter/MqttPacketBodyReader.cs Целия файл

@@ -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;


Зареждане…
Отказ
Запис