Skip to content
Open
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 @@ -27,18 +27,20 @@ internal static class LengthBuckets
return null;
}

int arraySize = spread * MaxPerLength;
long expectedArraySize = (long)spread * MaxPerLength;
#if NET
if (arraySize > Array.MaxLength)
if (expectedArraySize > Array.MaxLength)
#else
if (arraySize > 0X7FFFFFC7)
if (expectedArraySize > 0X7FFFFFC7)
#endif
{
// In the future we may lower the value, as it may be quite unlikely
// to have a LOT of strings of different sizes.
return null;
}

int arraySize = (int)expectedArraySize;

// Instead of creating a dictionary of lists or a multi-dimensional array
// we rent a single dimension array, where every bucket has five slots.
// The bucket starts at (key.Length - minLength) * 5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,19 @@ public void ContainsKey_WithNonAscii(int percentageWithNonAscii)

Assert.All(expected, kvp => actual.ContainsKey(kvp.Key));
}

[Fact]
[OuterLoop]
public void ToFrozenDictionary_WithExtremelyLargeStrings()
{
// Test case with extremely large strings that exceed length bucket boundaries.
var keys = new[] { "", new string('a', 0X7FFFFFC7 / 4) };
var frozen = keys.ToFrozenDictionary(s => s, GetKeyIEqualityComparer());
Assert.Equal(keys.Length, frozen.Count);
Assert.Equal(keys.Length, frozen.Keys.Length);
Assert.Equal(keys.Length, frozen.Values.Length);
Assert.All(keys, key => frozen.ContainsKey(key));
}
}

public class FrozenDictionary_Generic_Tests_string_string_Default : FrozenDictionary_Generic_Tests_string_string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ public void Contains_WithNonAscii(int percentageWithNonAscii)

Assert.All(expected, s => actual.Contains(s));
}

[Fact]
[OuterLoop]
public void ToFrozenSet_WithExtremelyLargeStrings()
{
// Test case with extremely large strings that exceed length bucket boundaries.
var keys = new[] { "", new string('a', 0X7FFFFFC7 / 4) };
var frozen = keys.ToFrozenSet(GetIEqualityComparer());
Assert.Equal(keys.Length, frozen.Count);
Assert.All(keys, key => frozen.Contains(key));
}
}

public class FrozenSet_Generic_Tests_string_Default : FrozenSet_Generic_Tests_string
Expand Down