From 6f313b026b7a09c2cfafbe11f65028c016a6958c Mon Sep 17 00:00:00 2001 From: bezzad Date: Sun, 17 Dec 2023 13:38:35 +0330 Subject: [PATCH] removed unused Merge method from Packet class --- src/Downloader.Test/UnitTests/PacketTest.cs | 22 --------------------- src/Downloader/Packet.cs | 19 ------------------ 2 files changed, 41 deletions(-) diff --git a/src/Downloader.Test/UnitTests/PacketTest.cs b/src/Downloader.Test/UnitTests/PacketTest.cs index 257d2f4a..f02c0b9f 100644 --- a/src/Downloader.Test/UnitTests/PacketTest.cs +++ b/src/Downloader.Test/UnitTests/PacketTest.cs @@ -25,26 +25,4 @@ public void CreatePacketTest() Assert.Equal(pos + len, packet.EndOffset); Assert.True(packet.Data.SequenceEqual(bytes)); } - - [Fact] - public void MergePacketsTest() - { - // arrange - var packetLength = 512; - var startPosA = 1024; - var startPosB = 1024; - var dataA = DummyData.GenerateOrderedBytes(1024); - var dataB = DummyData.GenerateSingleBytes(1024, 8); - var packetA = new Packet(startPosA, dataA, packetLength); - var packetB = new Packet(startPosB, dataB, packetLength); - var concatData = dataA.Take(packetLength).Concat(dataB.Take(packetLength)); - - // act - packetA.Merge(packetB); - - // assert - Assert.Equal(packetLength, packetB.Length); - Assert.Equal(packetLength * 2, packetA.Length); - Assert.True(packetA.Data.SequenceEqual(concatData)); - } } diff --git a/src/Downloader/Packet.cs b/src/Downloader/Packet.cs index 09d14c63..d4d8d68e 100644 --- a/src/Downloader/Packet.cs +++ b/src/Downloader/Packet.cs @@ -17,25 +17,6 @@ public Packet(long position, byte[] data, int len) Length = len; } - public bool Merge(Packet other) - { - lock (this) - { - if (IsDisposed) - return false; - - // fast merge - var combinedArray = new byte[Length + other.Length]; - Buffer.BlockCopy(Data, 0, combinedArray, 0, Length); - Buffer.BlockCopy(other.Data, 0, combinedArray, Length, other.Length); - - Data = combinedArray; - Length = combinedArray.Length; - - return true; - } - } - public void Dispose() { IsDisposed = true;