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 @@ -155,8 +155,7 @@ private void Extract_LinkEntry_TargetInsideDirectory_Internal(TarEntryType entry
[InlineData(512 + 512 - 1)]
public void Extract_UnseekableStream_BlockAlignmentPadding_DoesNotAffectNextEntries(int contentSize)
{
byte[] fileContents = new byte[contentSize];
Array.Fill<byte>(fileContents, 0x1);
byte[] fileContents = Array.CreateFilled<byte>(contentSize, 0x1);

using var archive = new MemoryStream();
using (var compressor = new GZipStream(archive, CompressionMode.Compress, leaveOpen: true))
Expand Down Expand Up @@ -493,9 +492,8 @@ public void PaxExtraction_PathTraversalInEA_IsBlocked()
[InlineData(100, 25)] // EA smaller than header
public void PaxExtraction_EntryLengthMatchesExtractedFileSize(int dataSize, long eaSize)
{
byte[] actualData = new byte[dataSize];
Array.Fill<byte>(actualData, (byte)'X');

byte[] actualData = Array.CreateFilled(dataSize, (byte)'X');

byte[] archive = BuildRawPaxArchiveWithSizeOverride("file.bin", "file.bin", actualData, dataSize, eaSize);

long apiLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ private async Task Extract_LinkEntry_TargetInsideDirectory_Internal_Async(TarEnt
[InlineData(512 + 512 - 1)]
public async Task Extract_UnseekableStream_BlockAlignmentPadding_DoesNotAffectNextEntries_Async(int contentSize)
{
byte[] fileContents = new byte[contentSize];
Array.Fill<byte>(fileContents, 0x1);
byte[] fileContents = Array.CreateFilled<byte>(contentSize, 0x1);

using var archive = new MemoryStream();
using (var compressor = new GZipStream(archive, CompressionMode.Compress, leaveOpen: true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public void MalformedArchive_TooSmall()
public void MalformedArchive_HeaderSize()
{
using MemoryStream malformed = new MemoryStream();
byte[] buffer = new byte[512]; // Minimum length of any header
Array.Fill<byte>(buffer, 0x1);
byte[] buffer = Array.CreateFilled<byte>(512, 0x1); // Minimum length of any header
malformed.Write(buffer);
malformed.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -71,8 +70,7 @@ public void LongEndMarkers_DoNotAdvanceStream()
writer.WriteEntry(entry);
}

byte[] buffer = new byte[2048]; // Four additional end markers (512 each)
Array.Fill<byte>(buffer, 0x0);
byte[] buffer = Array.CreateFilled<byte>(2048, 0x0); // Four additional end markers (512 each)
archive.Write(buffer);
archive.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -286,8 +284,7 @@ public void GetNextEntry_UnseekableArchive_ReplaceDataStream_ExcludeFromDisposin
[InlineData(512 + 512 - 1, true)]
public void BlockAlignmentPadding_DoesNotAffectNextEntries(int contentSize, bool copyData)
{
byte[] fileContents = new byte[contentSize];
Array.Fill<byte>(fileContents, 0x1);
byte[] fileContents = Array.CreateFilled<byte>(contentSize, 0x1);

using var archive = new MemoryStream();
using (var writer = new TarWriter(archive, leaveOpen: true))
Expand Down Expand Up @@ -478,9 +475,8 @@ public static IEnumerable<object[]> EASizeOverrideData()
[MemberData(nameof(EASizeOverrideData))]
public void PaxReader_EASizeOverridesHeaderSize(int actualDataSize, long headerSize, long eaSize)
{
byte[] actualData = new byte[actualDataSize];
Array.Fill<byte>(actualData, (byte)'X');

byte[] actualData = Array.CreateFilled(actualDataSize, (byte)'X');

byte[] archive = BuildRawPaxArchiveWithSizeOverride("file.bin", "file.bin", actualData, headerSize, eaSize);

using var stream = new MemoryStream(archive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public async Task MalformedArchive_HeaderSize_Async()
{
await using (MemoryStream malformed = new MemoryStream())
{
byte[] buffer = new byte[512]; // Minimum length of any header
Array.Fill<byte>(buffer, 0x1);
byte[] buffer = Array.CreateFilled<byte>(512, 0x1); // Minimum length of any header
malformed.Write(buffer);
malformed.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -82,8 +81,7 @@ public async Task LongEndMarkers_DoNotAdvanceStream_Async()
await writer.WriteEntryAsync(entry);
}

byte[] buffer = new byte[2048]; // Four additional end markers (512 each)
Array.Fill<byte>(buffer, 0x0);
byte[] buffer = Array.CreateFilled<byte>(2048, 0x0); // Four additional end markers (512 each)
archive.Write(buffer);
archive.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -309,9 +307,8 @@ public async Task GetNextEntry_UnseekableArchive_ReplaceDataStream_ExcludeFromDi
[InlineData(512 + 512 - 1, true)]
public async Task BlockAlignmentPadding_DoesNotAffectNextEntries_Async(int contentSize, bool copyData)
{
byte[] fileContents = new byte[contentSize];
Array.Fill<byte>(fileContents, 0x1);

byte[] fileContents = Array.CreateFilled<byte>(contentSize, 0x1);

using var archive = new MemoryStream();
using (var writer = new TarWriter(archive, leaveOpen: true))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ private static byte[] GetStaticLiteralTreeLength()

private static byte[] GetStaticDistanceTreeLength()
{
byte[] staticDistanceTreeLength = new byte[MaxDistTreeElements];
Array.Fill(staticDistanceTreeLength, (byte)5);
byte[] staticDistanceTreeLength = Array.CreateFilled<byte>(MaxDistTreeElements, 5);
return staticDistanceTreeLength;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,8 @@ public static async Task ZipArchiveEntry_CorruptedStream_EnsureNoExtraBytesReadO
// the window portion [0, s_bufferSize), so the tail [s_bufferSize, end) must
// never be touched regardless of how many iterations the loop takes.
const int sentinelSize = 64;
byte[] buffer = new byte[s_bufferSize + sentinelSize];
Array.Fill<byte>(buffer, 0xDE);

byte[] buffer = Array.CreateFilled<byte>(s_bufferSize + sentinelSize, 0xDE);

await Assert.ThrowsAsync<InvalidDataException>(async () =>
{
int read;
Expand Down
18 changes: 7 additions & 11 deletions src/libraries/System.Linq/tests/SumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ public void SumOfInt_SourceSumsToOverflow_OverflowExceptionThrown()
[Fact]
public void SumOfInt_SourceSumsToOverflowVectorHorizontally_OverflowExceptionThrown()
{
int[] sourceInt = new int[Vector<int>.Count * 4];
Array.Fill(sourceInt, 0);

int[] sourceInt = Array.CreateFilled(Vector<int>.Count * 4, 0);

for (int i = 0; i < Vector<int>.Count; i++)
{
sourceInt[i] = int.MaxValue - 3;
Expand All @@ -407,8 +406,7 @@ public void SumOfInt_SourceSumsToOverflowVectorHorizontally_OverflowExceptionThr
[MemberData(nameof(SumOverflowsVerticalVectorLanes))]
public void SumOfInt_SourceSumsToOverflowVectorVertically_OverflowExceptionThrown(int element, int verticalOffset)
{
int[] sourceInt = new int[Vector<int>.Count * 6];
Array.Fill(sourceInt, 0);
int[] sourceInt = Array.CreateFilled(Vector<int>.Count * 6, 0);

sourceInt[element] = int.MaxValue;
sourceInt[element + Vector<int>.Count * verticalOffset] = 1;
Expand All @@ -435,9 +433,8 @@ public void SumOfLong_SourceSumsToOverflow_OverflowExceptionThrown()
[Fact]
public void SumOfLong_SourceSumsToOverflowVectorHorizontally_OverflowExceptionThrown()
{
long[] sourceLong = new long[Vector<long>.Count * 4];
Array.Fill(sourceLong, 0);

long[] sourceLong = Array.CreateFilled<long>(Vector<long>.Count * 4, 0);

for (int i = 0; i < Vector<long>.Count; i++)
{
sourceLong[i] = long.MaxValue - 3;
Expand All @@ -454,9 +451,8 @@ public void SumOfLong_SourceSumsToOverflowVectorHorizontally_OverflowExceptionTh
[MemberData(nameof(SumOverflowsVerticalVectorLanes))]
public void SumOfLong_SourceSumsToOverflowVectorVertically_OverflowExceptionThrown(int element, int verticalOffset)
{
long[] sourceLong = new long[Vector<long>.Count * 6];
Array.Fill(sourceLong, 0);

long[] sourceLong = Array.CreateFilled<long>(Vector<long>.Count * 6, 0);

sourceLong[element] = long.MaxValue;
sourceLong[element + Vector<long>.Count * verticalOffset] = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static void AsReadOnlyRef()
Assert.Equal(0x11222211, asInt);
Assert.True(Unsafe.AreSame<byte>(ref Unsafe.As<int, byte>(ref Unsafe.AsRef(in asInt)), ref MemoryMarshal.GetReference(span)));

var array = new byte[100];
Array.Fill<byte>(array, 0x42);
byte[] array = Array.CreateFilled<byte>(100, 0x42);
ref readonly TestHelpers.TestStructExplicit asStruct = ref MemoryMarshal.AsRef<TestHelpers.TestStructExplicit>(new ReadOnlySpan<byte>(array));

Assert.Equal((uint)0x42424242, asStruct.UI1);
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/System.Memory/tests/MemoryMarshal/AsRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static void AsRef()
Assert.Equal(0x11222211, asInt);
Assert.True(Unsafe.AreSame<byte>(ref Unsafe.As<int, byte>(ref asInt), ref MemoryMarshal.GetReference(span)));

var array = new byte[100];
Array.Fill<byte>(array, 0x42);
byte[] array = Array.CreateFilled<byte>(100, 0x42);
ref TestHelpers.TestStructExplicit asStruct = ref MemoryMarshal.AsRef<TestHelpers.TestStructExplicit>(new Span<byte>(array));

Assert.Equal((uint)0x42424242, asStruct.UI1);
Expand Down
12 changes: 4 additions & 8 deletions src/libraries/System.Memory/tests/ReadOnlySpan/Count.byte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ public static void TestAlignmentNotCount_RosByte()
[Fact]
public static void TestAlignmentCount_Byte()
{
byte[] array = new byte[4 * Vector<byte>.Count];
Array.Fill(array, (byte)5);
byte[] array = Array.CreateFilled<byte>(4 * Vector<byte>.Count, 5);
for (var i = 0; i < Vector<byte>.Count; i++)
{
var span = new ReadOnlySpan<byte>(array, i, 3 * Vector<byte>.Count);
Expand All @@ -181,8 +180,7 @@ public static void TestAlignmentCount_Byte()
[Fact]
public static void TestAlignmentCount_RosByte()
{
byte[] array = new byte[4 * Vector<byte>.Count];
Array.Fill(array, (byte)5);
byte[] array = Array.CreateFilled<byte>(4 * Vector<byte>.Count, 5);
for (var i = 0; i < Vector<byte>.Count; i++)
{
var span = new ReadOnlySpan<byte>(array, i, 3 * Vector<byte>.Count);
Expand Down Expand Up @@ -260,10 +258,8 @@ public static void MakeSureNoCountChecksGoOutOfRange_RosByte()
[Fact]
public static void TestOverlapDoNotCount_RosByte()
{
byte[] a = new byte[10];
Array.Fill<byte>(a, 6);


byte[] a = Array.CreateFilled<byte>(10, 6);

var span = new ReadOnlySpan<byte>(a);
Assert.Equal(5, span.Count(new byte[] { 6, 6 }));
}
Expand Down
13 changes: 5 additions & 8 deletions src/libraries/System.Memory/tests/ReadOnlySpan/IndexOfAny.T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ public static void DefaultFilledIndexOfAny_TwoString()

for (int length = 0; length < byte.MaxValue; length++)
{
var a = new string[length];
Array.Fill(a, "");
string[] a = Array.CreateFilled(length, "");

string[] targets = { "", "99" };

Expand Down Expand Up @@ -634,9 +633,8 @@ public static void DefaultFilledIndexOfAny_ThreeString()

for (int length = 0; length < byte.MaxValue; length++)
{
var a = new string[length];
Array.Fill(a, "");

string[] a = Array.CreateFilled(length, "");

string[] targets = { "", "99", "98" };

for (int i = 0; i < length; i++)
Expand Down Expand Up @@ -782,9 +780,8 @@ public static void DefaultFilledIndexOfAny_ManyString()
{
for (int length = 0; length < byte.MaxValue; length++)
{
var a = new string[length];
Array.Fill(a, "");

string[] a = Array.CreateFilled(length, "");

var values = new string[] { "", "99", "98", "0" };

for (int i = 0; i < length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,8 @@ public static void DefaultFilledLastIndexOfAny_String_TwoByte()

for (int length = 0; length < byte.MaxValue; length++)
{
var a = new string[length];
Array.Fill(a, "");

string[] a = Array.CreateFilled(length, "");

string[] targets = { "", "99" };

for (int i = 0; i < length; i++)
Expand Down Expand Up @@ -624,8 +623,7 @@ public static void DefaultFilledLastIndexOfAny_String_ThreeByte()

for (int length = 0; length < byte.MaxValue; length++)
{
var a = new string[length];
Array.Fill(a, "");
string[] a = Array.CreateFilled(length, "");

string[] targets = { "", "99", "98" };

Expand Down Expand Up @@ -769,8 +767,7 @@ public static void DefaultFilledLastIndexOfAny_String_ManyByte()
{
for (int length = 0; length < byte.MaxValue; length++)
{
var a = new string[length];
Array.Fill(a, "");
string[] a = Array.CreateFilled(length, "");

var values = new string[] { "", "99", "98", "0" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ private static SafeChannelBindingHandle CreateChannelBinding(ChannelBindingKind
{
const int HashLength = 32;
SafeChannelBindingHandle handle = new SafeChannelBindingHandle(kind);
byte[] hash = new byte[HashLength];
Array.Fill(hash, hashSeed);
byte[] hash = Array.CreateFilled(HashLength, hashSeed);
handle.SetCertHash(hash);
return handle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2628,11 +2628,8 @@ public void HammingBitDistance_KnownValues()
T value42 = T.CreateTruncating(42);
T value84 = T.CreateTruncating(84);

T[] values1 = new T[100];
T[] values2 = new T[100];

Array.Fill(values1, value42);
Array.Fill(values2, value84);
T[] values1 = Array.CreateFilled(100, value42);
T[] values2 = Array.CreateFilled(100, value84);

Assert.Equal(0, TensorPrimitives.HammingBitDistance<T>(values1, values1));
Assert.Equal(600, TensorPrimitives.HammingBitDistance<T>(values1, values2));
Expand Down Expand Up @@ -2805,10 +2802,9 @@ public void Clamp_UnorderedBoundsMatchScalarSemantics(int length)
{
// Span x, span min, span max
{
T[] min = new T[length];
T[] max = new T[length];
Array.Fill(min, zero);
Array.Fill(max, two);
T[] min = Array.CreateFilled(length, zero);
T[] max = Array.CreateFilled(length, two);

min[offendingIndex] = two;
max[offendingIndex] = zero;

Expand All @@ -2822,8 +2818,7 @@ public void Clamp_UnorderedBoundsMatchScalarSemantics(int length)

// Span x, span min, scalar max
{
T[] min = new T[length];
Array.Fill(min, zero);
T[] min = Array.CreateFilled(length, zero);
min[offendingIndex] = two;

TensorPrimitives.Clamp<T>(x, min, one, destination);
Expand All @@ -2836,8 +2831,7 @@ public void Clamp_UnorderedBoundsMatchScalarSemantics(int length)

// Span x, scalar min, span max
{
T[] max = new T[length];
Array.Fill(max, two);
T[] max = Array.CreateFilled(length, two);
max[offendingIndex] = zero;

TensorPrimitives.Clamp<T>(x, one, max, destination);
Expand All @@ -2860,10 +2854,8 @@ public void Clamp_UnorderedBoundsMatchScalarSemantics(int length)

// Scalar x, span min, span max
{
T[] min = new T[length];
T[] max = new T[length];
Array.Fill(min, zero);
Array.Fill(max, two);
T[] min = Array.CreateFilled(length, zero);
T[] max = Array.CreateFilled(length, two);
min[offendingIndex] = two;
max[offendingIndex] = zero;

Expand All @@ -2877,8 +2869,7 @@ public void Clamp_UnorderedBoundsMatchScalarSemantics(int length)

// Scalar x, span min, scalar max
{
T[] min = new T[length];
Array.Fill(min, zero);
T[] min = Array.CreateFilled(length, zero);
min[offendingIndex] = two;

TensorPrimitives.Clamp<T>(one, min, one, destination);
Expand All @@ -2891,8 +2882,7 @@ public void Clamp_UnorderedBoundsMatchScalarSemantics(int length)

// Scalar x, scalar min, span max
{
T[] max = new T[length];
Array.Fill(max, two);
T[] max = Array.CreateFilled(length, two);
max[offendingIndex] = zero;

TensorPrimitives.Clamp<T>(one, one, max, destination);
Expand Down
Loading