(Binary.CopyOverlapped): use Buffer.BlockCopy when destination precedes source.

This commit is contained in:
morkt 2015-07-19 15:29:00 +04:00
parent 4f86894f9f
commit 7853d6a462

View File

@ -74,14 +74,21 @@ namespace GameRes.Utility
public static void CopyOverlapped (byte[] data, int src, int dst, int count) public static void CopyOverlapped (byte[] data, int src, int dst, int count)
{ {
int preceding = dst-src; int preceding = dst-src;
while (count > 0) if (preceding > 0)
{ {
if (preceding > count) while (count > 0)
preceding = count; {
System.Buffer.BlockCopy (data, src, data, dst, preceding); if (preceding > count)
src = dst; preceding = count;
dst += preceding; System.Buffer.BlockCopy (data, src, data, dst, preceding);
count -= preceding; src = dst;
dst += preceding;
count -= preceding;
}
}
else
{
System.Buffer.BlockCopy (data, src, data, dst, count);
} }
} }