Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
No-op ConcurrentStack.PushRange(T[]) if empty
Resolves #62121.
  • Loading branch information
martincostello committed Nov 29, 2021
commit d8e1bfb28ae4b7842f3ae92e48b1bbfefc50233e
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ public void PushRange(T[] items)
{
throw new ArgumentNullException(nameof(items));
}

// No op if the length is zero
if (items.Length == 0)
return;

PushRange(items, 0, items.Length);
}

Expand Down Expand Up @@ -349,7 +354,6 @@ public void PushRange(T[] items, int startIndex, int count)
if (count == 0)
return;


Node head, tail;
head = tail = new Node(items[startIndex]);
for (int i = startIndex + 1; i < startIndex + count; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public void PushRange_NoItems_NothingAdded()
Assert.True(s.IsEmpty);
}

[Fact]
public void PushRange_NoItems_NothingAdded_NoRangeSpecified()
{
var s = new ConcurrentStack<int>();
Assert.True(s.IsEmpty);

s.PushRange(new int[0]);
Assert.True(s.IsEmpty);
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[InlineData(8, 10)]
[InlineData(16, 100)]
Expand Down