Skip to content

Commit

Permalink
removed unused Merge method from Packet class
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Dec 17, 2023
1 parent 38a3dc9 commit 6f313b0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 41 deletions.
22 changes: 0 additions & 22 deletions src/Downloader.Test/UnitTests/PacketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
19 changes: 0 additions & 19 deletions src/Downloader/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f313b0

Please sign in to comment.