Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,12 @@ public void LinkSuffix(BlobBuilder suffix)
// The value is not used, other than for calculating the value of Count property.
suffix._previousLengthOrFrozenSuffixLengthDelta = suffixPreviousLength + oldSuffixLength - suffix.Length;

if (!isEmpty)
if (isEmpty)
{
var suffixLast = suffix._nextOrPrevious;
_nextOrPrevious = (suffixLast != suffix) ? suffixLast : this;
}
else
{
// First and last chunks:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,48 @@ public void LinkSuffix_Empty3()
Assert.Equal(16, builder2.Count);
}

[Fact]
public void LinkSuffix_EmptyDestination_SuffixAlreadyLinked()
Comment thread
MichalStrehovsky marked this conversation as resolved.
{
var emptyPrefix = new BlobBuilder(16);
var element = new BlobBuilder(16);
var tail = new BlobBuilder(16);

element.WriteByte(0x11);
tail.WriteByte(0x22);

element.LinkSuffix(tail);
emptyPrefix.LinkSuffix(element);

AssertEx.Equal(new byte[] { 0x11, 0x22 }, emptyPrefix.ToArray());
Assert.Equal(2, emptyPrefix.Count);
Assert.Equal(2, element.Count);
Assert.Equal(1, tail.Count);
}

[Fact]
public void LinkSuffix_EmptyDestination_SuffixThreeChunkChain()
{
var emptyPrefix = new BlobBuilder(16);
var first = new BlobBuilder(16);
var second = new BlobBuilder(16);
var third = new BlobBuilder(16);

first.WriteByte(0x11);
second.WriteByte(0x22);
third.WriteByte(0x33);

first.LinkSuffix(second);
first.LinkSuffix(third);
emptyPrefix.LinkSuffix(first);

AssertEx.Equal(new byte[] { 0x11, 0x22, 0x33 }, emptyPrefix.ToArray());
Assert.Equal(3, emptyPrefix.Count);
Assert.Equal(3, first.Count);
Assert.Equal(1, second.Count);
Assert.Equal(1, third.Count);
}

[Fact]
public void LinkPrefix1()
{
Expand Down
Loading