azist / azos

A to Z Sky Operating System / Microservice Chassis Framework
MIT License
213 stars 29 forks source link

BixReader.ReadFromStream - if the source is MemoryStream use block copy for performance #826

Open itadapter opened 1 year ago

itadapter commented 1 year ago

Test for memoryStream and use blockcopy instead

[MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void ReadFromStream(byte[] buffer, int count)
    {
      if (count <= 0) return;
      var total = 0;
      do
      {
        var got = m_Stream.Read(buffer, total, count - total);

        if (got < 1) //EOF
          throw new BixException(StringConsts.BIX_STREAM_CORRUPTED_ERROR + "ReadFromStream(Need: {0}; Got: {1})".Args(count, total));

        total += got;
      } while (total < count);
    }