Skip to content

Commit 54320e6

Browse files
committed
Removed redundant modifiers
1 parent cb2212b commit 54320e6

File tree

103 files changed

+393
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+393
-401
lines changed

src/DotNext.Benchmarks/Net/Cluster/Consensus/Raft/PersistentStateBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public async ValueTask<long> ReadAsync<TEntryImpl, TList>(TList entries, long? s
4545
where TList : notnull, IReadOnlyList<TEntryImpl>
4646
{
4747
var result = 0L;
48-
foreach (var entry in entries)
48+
for (var i = 0; i < entries.Count; i++)
4949
{
50-
using var buffer = await entry.ToMemoryAsync();
50+
using var buffer = await entries[i].ToMemoryAsync(token: token);
5151
result += buffer.Length;
5252
}
5353

src/DotNext.IO/Buffers/BufferWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static int Write(this ref BufferWriterSlim<byte> writer, scoped ReadOnlyS
196196
}
197197

198198
private static bool TryFormat<T>(IBufferWriter<byte> writer, T value, Span<char> buffer, in EncodingContext context, LengthFormat? lengthFormat, ReadOnlySpan<char> format, IFormatProvider? provider, out long bytesWritten)
199-
where T : notnull, ISpanFormattable
199+
where T : ISpanFormattable
200200
{
201201
if (!value.TryFormat(buffer, out var charsWritten, format, provider))
202202
{
@@ -228,7 +228,7 @@ private static bool TryFormat<T>(IBufferWriter<byte> writer, T value, Span<char>
228228
/// <returns>The number of written bytes.</returns>
229229
[SkipLocalsInit]
230230
public static long Format<T>(this IBufferWriter<byte> writer, T value, in EncodingContext context, LengthFormat? lengthFormat, ReadOnlySpan<char> format = default, IFormatProvider? provider = null, MemoryAllocator<char>? allocator = null)
231-
where T : notnull, ISpanFormattable
231+
where T : ISpanFormattable
232232
{
233233
// attempt to allocate char buffer on the stack
234234
Span<char> charBuffer = stackalloc char[SpanOwner<char>.StackallocThreshold];
@@ -259,7 +259,7 @@ public static long Format<T>(this IBufferWriter<byte> writer, T value, in Encodi
259259
/// <returns>The number of written bytes.</returns>
260260
/// <exception cref="InsufficientMemoryException"><paramref name="writer"/> has not enough free space to place UTF-8 bytes.</exception>
261261
public static int Format<T>(this IBufferWriter<byte> writer, T value, LengthFormat? lengthFormat, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
262-
where T : notnull, IUtf8SpanFormattable
262+
where T : IUtf8SpanFormattable
263263
{
264264
var expectedLengthSize = lengthFormat switch
265265
{

src/DotNext.IO/Buffers/IBufferReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void IReadOnlySpanConsumer<byte>.Invoke(ReadOnlySpan<byte> source)
6060

6161
[StructLayout(LayoutKind.Auto)]
6262
internal unsafe struct WellKnownIntegerReader<T>(delegate*<ReadOnlySpan<byte>, bool, T> parser) : IBufferReader, ISupplier<T>
63-
where T : notnull, IBinaryInteger<T>
63+
where T : IBinaryInteger<T>
6464
{
6565
private T? buffer;
6666
private int writtenBytes;
@@ -84,7 +84,7 @@ void IReadOnlySpanConsumer<byte>.Invoke(ReadOnlySpan<byte> source)
8484

8585
[StructLayout(LayoutKind.Auto)]
8686
internal unsafe struct IntegerReader<T>(delegate*<ReadOnlySpan<byte>, bool, T> parser) : IBufferReader, ISupplier<T>
87-
where T : notnull, IBinaryInteger<T>
87+
where T : IBinaryInteger<T>
8888
{
8989
private MemoryOwner<byte> buffer = Memory.AllocateExactly<byte>(Number.GetMaxByteCount<T>());
9090
private int writtenBytes;
@@ -116,7 +116,7 @@ T ISupplier<T>.Invoke()
116116

117117
[StructLayout(LayoutKind.Auto)]
118118
internal struct BinaryFormattable256Reader<T> : IBufferReader, ISupplier<T>
119-
where T : notnull, IBinaryFormattable<T>
119+
where T : IBinaryFormattable<T>
120120
{
121121
private Buffer256 buffer;
122122
private int writtenBytes;
@@ -141,7 +141,7 @@ readonly T ISupplier<T>.Invoke()
141141

142142
[StructLayout(LayoutKind.Auto)]
143143
internal struct BinaryFormattableReader<T>() : IBufferReader, ISupplier<T>
144-
where T : notnull, IBinaryFormattable<T>
144+
where T : IBinaryFormattable<T>
145145
{
146146
private MemoryOwner<byte> buffer = Memory.AllocateExactly<byte>(T.Size);
147147
private int writtenBytes;

src/DotNext.IO/IO/DataTransferObject.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ValueTask<T> IDataTransferObject.ITransformation<T>.TransformAsync<TReader>(TRea
4747
/// <returns>The task representing state of asynchronous execution.</returns>
4848
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
4949
public static ValueTask WriteToAsync<TObject>(this TObject dto, Stream output, Memory<byte> buffer, CancellationToken token = default)
50-
where TObject : notnull, IDataTransferObject
50+
where TObject : IDataTransferObject
5151
=> dto.WriteToAsync(new AsyncStreamBinaryAccessor(output, buffer), token);
5252

5353
/// <summary>
@@ -61,7 +61,7 @@ public static ValueTask WriteToAsync<TObject>(this TObject dto, Stream output, M
6161
/// <returns>The task representing state of asynchronous execution.</returns>
6262
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
6363
public static ValueTask WriteToAsync<TObject>(this TObject dto, Stream output, int bufferSize = DefaultBufferSize, CancellationToken token = default)
64-
where TObject : notnull, IDataTransferObject
64+
where TObject : IDataTransferObject
6565
{
6666
return dto.TryGetMemory(out var memory) ?
6767
output.WriteAsync(memory, token) :
@@ -85,7 +85,7 @@ static async ValueTask WriteToStreamAsync(TObject dto, Stream output, int buffer
8585
/// <returns>The task representing state of asynchronous execution.</returns>
8686
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
8787
public static ValueTask WriteToAsync<TObject>(this TObject dto, PipeWriter output, long bufferSize = 0L, CancellationToken token = default)
88-
where TObject : notnull, IDataTransferObject
88+
where TObject : IDataTransferObject
8989
{
9090
return bufferSize >= 0L
9191
? dto.WriteToAsync(new PipeBinaryWriter(output, bufferSize), token)
@@ -102,7 +102,7 @@ public static ValueTask WriteToAsync<TObject>(this TObject dto, PipeWriter outpu
102102
/// <returns>The task representing state of asynchronous execution.</returns>
103103
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
104104
public static ValueTask WriteToAsync<TObject>(this TObject dto, IBufferWriter<byte> writer, CancellationToken token = default)
105-
where TObject : notnull, IDataTransferObject
105+
where TObject : IDataTransferObject
106106
{
107107
ValueTask result;
108108
if (dto.TryGetMemory(out var memory))
@@ -136,7 +136,7 @@ public static ValueTask WriteToAsync<TObject>(this TObject dto, IBufferWriter<by
136136
/// <returns>The content of the object.</returns>
137137
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
138138
public static ValueTask<string> ToStringAsync<TObject>(this TObject dto, Encoding encoding, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
139-
where TObject : notnull, IDataTransferObject
139+
where TObject : IDataTransferObject
140140
{
141141
ValueTask<string> result;
142142

@@ -186,7 +186,7 @@ static async ValueTask<string> DecodeAsync(TObject dto, Encoding encoding, Memor
186186
/// <returns>The content of the object.</returns>
187187
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
188188
public static ValueTask<byte[]> ToByteArrayAsync<TObject>(this TObject dto, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
189-
where TObject : notnull, IDataTransferObject
189+
where TObject : IDataTransferObject
190190
{
191191
ValueTask<byte[]> result;
192192

@@ -236,7 +236,7 @@ static async ValueTask<byte[]> BufferizeAsync(TObject dto, MemoryAllocator<byte>
236236
/// <returns>The content of the object.</returns>
237237
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
238238
public static ValueTask<MemoryOwner<byte>> ToMemoryAsync<TObject>(this TObject dto, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
239-
where TObject : notnull, IDataTransferObject
239+
where TObject : IDataTransferObject
240240
{
241241
ValueTask<MemoryOwner<byte>> result;
242242

@@ -287,6 +287,6 @@ static async ValueTask<MemoryOwner<byte>> BufferizeAsync(TObject dto, MemoryAllo
287287
/// <returns>The converted DTO content.</returns>
288288
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
289289
public static ValueTask<TResult> TransformAsync<TResult, TObject>(this TObject dto, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>> transformation, CancellationToken token = default)
290-
where TObject : notnull, IDataTransferObject
290+
where TObject : IDataTransferObject
291291
=> dto.TransformAsync<TResult, DelegatingDecoder<TResult>>(new DelegatingDecoder<TResult>(transformation), token);
292292
}

src/DotNext.IO/IO/EncodingTextWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override void Write(ReadOnlySpan<char> chars)
2222
=> Encoding.GetBytes(chars, writer);
2323

2424
private void WriteFormattable<T>(T value)
25-
where T : notnull, ISpanFormattable
25+
where T : ISpanFormattable
2626
{
2727
var writer = new BufferWriterSlim<char>(stackalloc char[ConversionBufferSize]);
2828
try

src/DotNext.IO/IO/FileBufferingWriter.cs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public override Span<byte> GetSpan()
7171

7272
public override Memory<byte> Memory => CreateMemory(length);
7373

74-
public override MemoryHandle Pin(int elementIndex)
74+
public override MemoryHandle Pin(int elementIndex = 0)
7575
{
7676
ObjectDisposedException.ThrowIf(ptr is null, this);
7777
return new(Unsafe.Add<byte>(ptr, elementIndex));
@@ -117,7 +117,7 @@ public override Span<byte> GetSpan()
117117

118118
public override Memory<byte> Memory => memory;
119119

120-
public override MemoryHandle Pin(int elementIndex)
120+
public override MemoryHandle Pin(int elementIndex = 0)
121121
=> memory.Slice(elementIndex).Pin();
122122

123123
public override void Unpin()
@@ -392,79 +392,79 @@ private void PersistBuffer(bool flushToDisk)
392392
}
393393

394394
/// <inheritdoc/>
395-
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken token = default)
395+
public override ValueTask WriteAsync(ReadOnlyMemory<byte> input, CancellationToken token = default)
396396
{
397397
if (IsReading)
398398
return ValueTask.FromException(new InvalidOperationException(ExceptionMessages.WriterInReadMode));
399399

400-
switch (PrepareMemory(buffer.Length, out var output))
400+
switch (PrepareMemory(input.Length, out var output))
401401
{
402402
default:
403403
return ValueTask.CompletedTask;
404404
case MemoryEvaluationResult.Success:
405-
buffer.CopyTo(output);
406-
position += buffer.Length;
405+
input.CopyTo(output);
406+
position += input.Length;
407407
goto default;
408408
case MemoryEvaluationResult.PersistExistingBuffer:
409-
return PersistExistingBufferAsync(buffer, token);
409+
return PersistExistingBufferAsync(input, token);
410410
case MemoryEvaluationResult.PersistAll:
411-
return PersistAllAsync(buffer, token);
411+
return PersistAllAsync(input, token);
412412
}
413413
}
414414

415-
private ValueTask PersistExistingBufferAsync(ReadOnlyMemory<byte> buffer, CancellationToken token)
415+
private ValueTask PersistExistingBufferAsync(ReadOnlyMemory<byte> input, CancellationToken token)
416416
{
417417
Debug.Assert(HasBufferedData);
418418

419419
EnsureBackingStore();
420-
secondBuffer = buffer;
420+
secondBuffer = input;
421421
return Submit(RandomAccess.WriteAsync(fileBackend, WrittenMemory, filePosition, token), writeAndCopyCallback);
422422
}
423423

424-
private ValueTask PersistAllAsync(ReadOnlyMemory<byte> buffer, CancellationToken token)
424+
private ValueTask PersistAllAsync(ReadOnlyMemory<byte> input, CancellationToken token)
425425
{
426426
EnsureBackingStore();
427427

428428
ValueTask task;
429429
if (HasBufferedData)
430430
{
431-
secondBuffer = buffer;
431+
secondBuffer = input;
432432
task = RandomAccess.WriteAsync(fileBackend, (IReadOnlyList<ReadOnlyMemory<byte>>)this.As<IDynamicInterfaceCastable>(), filePosition, token);
433433
}
434434
else
435435
{
436-
position = buffer.Length;
437-
task = RandomAccess.WriteAsync(fileBackend, buffer, filePosition, token);
436+
position = input.Length;
437+
task = RandomAccess.WriteAsync(fileBackend, input, filePosition, token);
438438
}
439439

440440
return Submit(task, writeCallback);
441441
}
442442

443-
/// <inheritdoc/>
444-
public override void Write(ReadOnlySpan<byte> buffer)
443+
/// <inheritdoc cref="Stream.Write(ReadOnlySpan{byte})"/>
444+
public override void Write(ReadOnlySpan<byte> input)
445445
{
446446
if (IsReading)
447447
throw new InvalidOperationException(ExceptionMessages.WriterInReadMode);
448448

449-
switch (PrepareMemory(buffer.Length, out var output))
449+
switch (PrepareMemory(input.Length, out var output))
450450
{
451451
case MemoryEvaluationResult.Success:
452-
buffer.CopyTo(output.Span);
453-
position += buffer.Length;
452+
input.CopyTo(output.Span);
453+
position += input.Length;
454454
break;
455455
case MemoryEvaluationResult.PersistExistingBuffer:
456456
PersistBuffer(flushToDisk: false);
457-
buffer.CopyTo(this.buffer.Span);
458-
position = buffer.Length;
457+
input.CopyTo(this.buffer.Span);
458+
position = input.Length;
459459
break;
460460
case MemoryEvaluationResult.PersistAll:
461461
if (HasBufferedData)
462462
PersistBuffer(flushToDisk: false);
463463
else
464464
EnsureBackingStore();
465465

466-
RandomAccess.Write(fileBackend, buffer, filePosition);
467-
filePosition += buffer.Length;
466+
RandomAccess.Write(fileBackend, input, filePosition);
467+
filePosition += input.Length;
468468
break;
469469
}
470470
}
@@ -473,28 +473,28 @@ public override void Write(ReadOnlySpan<byte> buffer)
473473
private void EnsureBackingStore() => fileBackend ??= fileProvider.CreateBackingFileHandle(position, out fileName);
474474

475475
/// <inheritdoc/>
476-
public override void Write(byte[] buffer, int offset, int count)
476+
public override void Write(byte[] data, int offset, int count)
477477
{
478-
ValidateBufferArguments(buffer, offset, count);
479-
Write(new ReadOnlySpan<byte>(buffer, offset, count));
478+
ValidateBufferArguments(data, offset, count);
479+
Write(new ReadOnlySpan<byte>(data, offset, count));
480480
}
481481

482482
/// <inheritdoc/>
483-
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
484-
=> WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), token).AsTask();
483+
public override Task WriteAsync(byte[] data, int offset, int count, CancellationToken token)
484+
=> WriteAsync(new ReadOnlyMemory<byte>(data, offset, count), token).AsTask();
485485

486486
/// <inheritdoc/>
487487
public override void WriteByte(byte value)
488488
=> Write(new(ref value));
489489

490490
/// <inheritdoc/>
491-
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
492-
=> TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), callback, state);
491+
public override IAsyncResult BeginWrite(byte[] data, int offset, int count, AsyncCallback? callback, object? state)
492+
=> TaskToAsyncResult.Begin(WriteAsync(data, offset, count), callback, state);
493493

494494
/// <inheritdoc/>
495495
public override void EndWrite(IAsyncResult ar) => TaskToAsyncResult.End(ar);
496496

497-
/// <inheritdoc/>
497+
/// <inheritdoc cref="Stream.Flush()"/>
498498
public override void Flush() => Flush(flushToDisk: false);
499499

500500
/// <summary>
@@ -553,7 +553,7 @@ public ValueTask FlushAsync(bool flushToDisk, CancellationToken token = default)
553553
return result;
554554
}
555555

556-
/// <inheritdoc/>
556+
/// <inheritdoc cref="Stream.FlushAsync(CancellationToken)"/>
557557
public override Task FlushAsync(CancellationToken token)
558558
=> FlushAsync(flushToDisk: false, token).AsTask();
559559

@@ -562,23 +562,23 @@ public override int ReadByte()
562562
=> throw new NotSupportedException();
563563

564564
/// <inheritdoc/>
565-
public override int Read(byte[] buffer, int offset, int count)
565+
public override int Read(byte[] data, int offset, int count)
566566
=> throw new NotSupportedException();
567567

568568
/// <inheritdoc/>
569-
public override int Read(Span<byte> buffer)
569+
public override int Read(Span<byte> data)
570570
=> throw new NotSupportedException();
571571

572572
/// <inheritdoc/>
573-
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken token)
573+
public override Task<int> ReadAsync(byte[] data, int offset, int count, CancellationToken token)
574574
=> Task.FromException<int>(new NotSupportedException());
575575

576576
/// <inheritdoc/>
577-
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken token)
577+
public override ValueTask<int> ReadAsync(Memory<byte> data, CancellationToken token = default)
578578
=> ValueTask.FromException<int>(new NotSupportedException());
579579

580580
/// <inheritdoc/>
581-
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
581+
public override IAsyncResult BeginRead(byte[] data, int offset, int count, AsyncCallback? callback, object? state)
582582
=> throw new NotSupportedException();
583583

584584
/// <inheritdoc/>
@@ -599,15 +599,15 @@ public override void SetLength(long value)
599599
/// <returns>The task representing asynchronous execution of this method.</returns>
600600
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
601601
public async Task CopyToAsync<TConsumer>(TConsumer consumer, int bufferSize, CancellationToken token)
602-
where TConsumer : notnull, ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
602+
where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
603603
{
604604
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bufferSize);
605605

606606
if (fileBackend is not null)
607607
{
608608
using var buffer = allocator.AllocateAtLeast(bufferSize);
609609
int count;
610-
for (long offset = 0L; (count = await RandomAccess.ReadAsync(fileBackend, buffer.Memory, offset, token).ConfigureAwait(false)) > 0; offset += count)
610+
for (var offset = 0L; (count = await RandomAccess.ReadAsync(fileBackend, buffer.Memory, offset, token).ConfigureAwait(false)) > 0; offset += count)
611611
await consumer.Invoke(buffer.Memory.Slice(0, count), token).ConfigureAwait(false);
612612
}
613613

@@ -628,13 +628,13 @@ ValueTask IGrowableBuffer<byte>.CopyToAsync<TConsumer>(TConsumer consumer, Cance
628628
/// <param name="token">The token that can be used to cancel the operation.</param>
629629
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
630630
public void CopyTo<TConsumer>(TConsumer consumer, int bufferSize, CancellationToken token)
631-
where TConsumer : notnull, IReadOnlySpanConsumer<byte>
631+
where TConsumer : IReadOnlySpanConsumer<byte>
632632
{
633633
if (fileBackend is not null)
634634
{
635635
using var buffer = allocator.AllocateAtLeast(bufferSize);
636636
int count;
637-
for (long offset = 0L; (count = RandomAccess.Read(fileBackend, buffer.Span, offset)) > 0; offset += count, token.ThrowIfCancellationRequested())
637+
for (var offset = 0L; (count = RandomAccess.Read(fileBackend, buffer.Span, offset)) > 0; offset += count, token.ThrowIfCancellationRequested())
638638
consumer.Invoke(buffer.Span.Slice(0, count));
639639
}
640640

0 commit comments

Comments
 (0)