You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReadOnlySequence.Slice(int start, int length) has (possibly) unexpected behavior #67607
I'm not sure whether this is a bug or expected behavior but calling ReadOnlySequence.Slice(int start, int length) on a sequence with more than one segment with a start index of 0 and length equal to the size of the first segment, returns a sequence with two segments where the second one is empty (this actually happen for slices of any size, as long as they are on a segment border, and regardless of whether we start from the beginning of the first segment or the beginning of any other segment)
Reproduction Steps
usingSystem.Buffers;varbuffer=newbyte[4097];varseg1=newSeg(buffer.AsMemory(^1),4096);varseg0=newSeg(buffer.AsMemory(..^1),0);seg0.SetNext(seg1);varsequence=newReadOnlySequence<byte>(seg0,0,seg1,1);varresult=sequence.Slice(0,sequence.First.Length);Console.WriteLine(result.IsSingleSegment);// this prints False internalclassSeg:ReadOnlySequenceSegment<byte>{publicSeg(ReadOnlyMemory<byte>memory,longrunningIndex){Memory=memory;RunningIndex=runningIndex;}publicvoidSetNext(Segseg){Next=seg;}}
Expected behavior
When slicing a sequence on segments border, I expect to get a sequence which contains only the sliced segments.
Actual behavior
Currently, slicing as described adds an empty segment at the end of the sequence.
Regression?
No response
Known Workarounds
No response
Configuration
NET 6.0 (but I also tried with the latest 7.0 preview)
Windows 10 x64
changed the title [-]ReadOnlySequence.Slice(int start, int length) has (perhaps) unexpected behavior [/-][+]ReadOnlySequence.Slice(int start, int length) has (possibly) unexpected behavior [/+]on Apr 6, 2022
Activity
[-]ReadOnlySequence.Slice(int start, int length) has (perhaps) unexpected behavior [/-][+]ReadOnlySequence.Slice(int start, int length) has (possibly) unexpected behavior [/+]davidfowl commentedon May 3, 2022
I think this is a read only sequence issue.
danmoseley commentedon May 3, 2022
Is it possible to give a repro snippet that is only in terms of span/sequence and not pipes?
davidfowl commentedon May 3, 2022
Tangentially related to #30786
davidfowl commentedon May 3, 2022
I updated the issue