make more use of stream.CopyTo on (de)compressors, plus several cosmetics

This commit is contained in:
UbitUmarov
2025-06-19 20:11:42 +01:00
parent 6180fe5340
commit 4b1df46f6a
14 changed files with 47 additions and 66 deletions

View File

@@ -26,6 +26,7 @@
*/
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
@@ -804,18 +805,18 @@ namespace OpenSim.Framework
/// </remarks>
public static int CopyStream(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy)
{
byte[] buffer = new byte[4096];
byte[] buffer = ArrayPool<byte>.Shared.Rent(8196);
int readBytes;
int totalCopiedBytes = 0;
while ((readBytes = copyFrom.Read(buffer, 0, Math.Min(4096, maximumBytesToCopy))) > 0)
while ((readBytes = copyFrom.Read(buffer, 0, Math.Min(8196, maximumBytesToCopy))) > 0)
{
int writeBytes = Math.Min(maximumBytesToCopy, readBytes);
copyTo.Write(buffer, 0, writeBytes);
totalCopiedBytes += writeBytes;
maximumBytesToCopy -= writeBytes;
}
ArrayPool<byte>.Shared.Return(buffer);
return totalCopiedBytes;
}