Skip to content

Commit bd49681

Browse files
paulomorgadoSergio0694
authored andcommitted
Change the 'position' field to be 'long'
1 parent 5aae6fc commit bd49681

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/CommunityToolkit.HighPerformance/Streams/ReadOnlySequenceStream.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal sealed partial class ReadOnlySequenceStream : Stream
2424
/// <summary>
2525
/// The current position within <see cref="source"/>.
2626
/// </summary>
27-
private int position;
27+
private long position;
2828

2929
/// <summary>
3030
/// Indicates whether or not the current instance has been disposed
@@ -90,7 +90,7 @@ public sealed override long Position
9090
MemoryStream.ValidateDisposed(this.disposed);
9191
MemoryStream.ValidatePosition(value, this.source.Length);
9292

93-
this.position = unchecked((int)value);
93+
this.position = value;
9494
}
9595
}
9696

@@ -123,9 +123,9 @@ public sealed override Task CopyToAsync(Stream destination, int bufferSize, Canc
123123

124124
if (this.source.IsSingleSegment)
125125
{
126-
ReadOnlyMemory<byte> buffer = this.source.First.Slice(this.position);
126+
ReadOnlyMemory<byte> buffer = this.source.First.Slice(unchecked((int)this.position));
127127

128-
this.position = (int)this.source.Length;
128+
this.position = this.source.Length;
129129

130130
return destination.WriteAsync(buffer, cancellationToken).AsTask();
131131
}
@@ -134,7 +134,7 @@ async Task CoreCopyToAsync(Stream destination, CancellationToken cancellationTok
134134
{
135135
ReadOnlySequence<byte> sequence = this.source.Slice(this.position);
136136

137-
this.position = (int)this.source.Length;
137+
this.position = this.source.Length;
138138

139139
foreach (ReadOnlyMemory<byte> segment in sequence)
140140
{
@@ -220,7 +220,7 @@ public sealed override long Seek(long offset, SeekOrigin origin)
220220

221221
MemoryStream.ValidatePosition(index, this.source.Length);
222222

223-
this.position = unchecked((int)index);
223+
this.position = index;
224224

225225
return index;
226226
}
@@ -253,6 +253,7 @@ public sealed override int Read(byte[]? buffer, int offset, int count)
253253
segment.Span.Slice(0, bytesToCopy).CopyTo(destination);
254254

255255
destination = destination.Slice(bytesToCopy);
256+
256257
bytesCopied += bytesToCopy;
257258

258259
this.position += bytesToCopy;

0 commit comments

Comments
 (0)