Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a32b943
Fix range checks in System.Collections.Immutable helpers for consiste…
Copilot Apr 19, 2026
371d011
Convert redundant Requires.Range to Debug.Assert in Node.BinarySearch
Copilot Apr 19, 2026
625bbda
Convert redundant checks in Node.Sort and Node.Reverse to Debug.Assert
Copilot Apr 19, 2026
5c1e0b0
Add Requires.ValidateRange shared helper and normalize blank lines af…
Copilot Apr 19, 2026
77cc8cc
Apply Requires.ValidateRange to ImmutableArray and ImmutableArray.Bui…
Copilot Apr 19, 2026
06ce702
Replace duplicated Requires.* with Debug.Assert in ImmutableList<T>.Node
Copilot Apr 19, 2026
ff4da43
Move validation from Node to public API surface; convert Node checks …
Copilot Apr 20, 2026
e91d47a
Add blank lines after Requires blocks; update ValidateRange to use De…
Copilot Apr 20, 2026
0df4554
Drop 'startIndex == 0 && count == 0' fast paths; add Requires.Validat…
Copilot Apr 20, 2026
426c717
Replace separate arrayIndex checks with overflow-safe combined form; …
Copilot Apr 20, 2026
5092452
Remove extension method LastIndexOf fast path; add overflow and empty…
Copilot Apr 20, 2026
33730cc
Replace two-line CopyTo range checks with single overflow-safe check …
Copilot Apr 20, 2026
4d21fe0
Add CopyTo and IndexOf overflow validation tests for immutable collec…
Copilot Apr 20, 2026
383214f
Remove unnecessary success-path CopyTo call from SortedSet builder test
Copilot Apr 20, 2026
1ddc14e
Optimize intermediate IndexOf/LastIndexOf overloads to validate index…
Copilot Apr 20, 2026
2717ba7
Revert "Optimize intermediate IndexOf/LastIndexOf overloads to valida…
Copilot Apr 20, 2026
3316976
Merge remote-tracking branch 'origin/main' into copilot/fix-range-che…
Copilot Apr 20, 2026
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 @@ -798,8 +798,7 @@ public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equa
return -1;
}

Requires.Range(startIndex >= 0 && startIndex <= this.Count, nameof(startIndex));
Requires.Range(count >= 0 && (uint)(startIndex + count) <= (uint)this.Count, nameof(count));
Requires.ValidateRange(startIndex, count, this.Count, nameof(startIndex));

equalityComparer ??= EqualityComparer<T>.Default;
if (equalityComparer == EqualityComparer<T>.Default)
Expand Down Expand Up @@ -1002,8 +1001,7 @@ public void Sort(int index, int count, IComparer<T>? comparer)
{
// Don't rely on Array.Sort's argument validation since our internal array may exceed
// the bounds of the publicly addressable region.
Requires.Range(index >= 0, nameof(index));
Requires.Range(count >= 0 && index + count <= this.Count, nameof(count));
Requires.ValidateRange(index, count, this.Count);

if (count > 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equa
return -1;
}

Requires.Range(startIndex >= 0 && startIndex <= self.Length, nameof(startIndex));
Requires.Range(count >= 0 && (uint)(startIndex + count) <= (uint)self.Length, nameof(count));
Requires.ValidateRange(startIndex, count, self.Length, nameof(startIndex));

equalityComparer ??= EqualityComparer<T>.Default;
if (equalityComparer == EqualityComparer<T>.Default)
Expand Down Expand Up @@ -826,8 +825,7 @@ public ImmutableArray<T> Sort(int index, int count, IComparer<T>? comparer)
{
ImmutableArray<T> self = this;
self.ThrowNullRefIfNotInitialized();
Requires.Range(index >= 0, nameof(index));
Requires.Range(count >= 0 && index + count <= self.Length, nameof(count));
Requires.ValidateRange(index, count, self.Length);

// 0 and 1 element arrays don't need to be sorted.
if (count > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ void IDictionary.Remove(object key)
void ICollection.CopyTo(Array array, int arrayIndex)
{
Requires.NotNull(array, nameof(array));
Requires.Range(arrayIndex >= 0, nameof(arrayIndex));
Requires.Range(array.Length >= arrayIndex + this.Count, nameof(arrayIndex));
Requires.Range(arrayIndex >= 0 && (uint)(arrayIndex + this.Count) <= (uint)array.Length, nameof(arrayIndex));

foreach (KeyValuePair<TKey, TValue> item in this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,7 @@ bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> i
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
{
Requires.NotNull(array, nameof(array));
Requires.Range(arrayIndex >= 0, nameof(arrayIndex));
Requires.Range(array.Length >= arrayIndex + this.Count, nameof(arrayIndex));
Requires.Range(arrayIndex >= 0 && (uint)(arrayIndex + this.Count) <= (uint)array.Length, nameof(arrayIndex));

foreach (KeyValuePair<TKey, TValue> item in this)
{
Expand Down Expand Up @@ -756,8 +755,7 @@ void IDictionary.Clear()
void ICollection.CopyTo(Array array, int arrayIndex)
{
Requires.NotNull(array, nameof(array));
Requires.Range(arrayIndex >= 0, nameof(arrayIndex));
Requires.Range(array.Length >= arrayIndex + this.Count, nameof(arrayIndex));
Requires.Range(arrayIndex >= 0 && (uint)(arrayIndex + this.Count) <= (uint)array.Length, nameof(arrayIndex));

foreach (KeyValuePair<TKey, TValue> item in this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ void ICollection<T>.Add(T item)
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
Requires.NotNull(array, nameof(array));
Requires.Range(arrayIndex >= 0, nameof(arrayIndex));
Requires.Range(array.Length >= arrayIndex + this.Count, nameof(arrayIndex));
Requires.Range(arrayIndex >= 0 && (uint)(arrayIndex + this.Count) <= (uint)array.Length, nameof(arrayIndex));

foreach (T item in this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,7 @@ bool ICollection<T>.IsReadOnly
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
Requires.NotNull(array, nameof(array));
Requires.Range(arrayIndex >= 0, nameof(arrayIndex));
Requires.Range(array.Length >= arrayIndex + this.Count, nameof(arrayIndex));
Requires.Range(arrayIndex >= 0 && (uint)(arrayIndex + this.Count) <= (uint)array.Length, nameof(arrayIndex));

foreach (T item in this)
{
Expand Down Expand Up @@ -537,8 +536,7 @@ bool ICollection<T>.Remove(T item)
void ICollection.CopyTo(Array array, int arrayIndex)
{
Requires.NotNull(array, nameof(array));
Requires.Range(arrayIndex >= 0, nameof(arrayIndex));
Requires.Range(array.Length >= arrayIndex + this.Count, nameof(arrayIndex));
Requires.Range(arrayIndex >= 0 && (uint)(arrayIndex + this.Count) <= (uint)array.Length, nameof(arrayIndex));

foreach (T item in this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,6 @@ public static int LastIndexOf<T>(this IImmutableList<T> list, T item, int startI
{
Requires.NotNull(list, nameof(list));

if (list.Count == 0 && startIndex == 0)
{
return -1;
}

return list.LastIndexOf(item, startIndex, startIndex + 1, EqualityComparer<T>.Default);
}

Expand Down
Loading
Loading