Skip to content

Commit f32fd66

Browse files
committed
nit: TryGetNextBuffer - defer updating result; empty segments are v.rare
1 parent fb2e506 commit f32fd66

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libraries/System.Memory/src/System/Buffers/SequenceReader.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ private static TryGetNextBufferResult TryGetNextBuffer(in ReadOnlySequence<T> se
330330
{
331331
while (!ReferenceEquals(segment, endObject) && (@object = segment = segment!.Next) is not null)
332332
{
333-
result = TryGetNextBufferResult.FailureAllRemainingSegmentsEmpty; // until we know otherwise
334333
buffer = segment!.Memory.Span;
335334

336335
if (ReferenceEquals(segment, endObject))
@@ -344,6 +343,9 @@ private static TryGetNextBufferResult TryGetNextBuffer(in ReadOnlySequence<T> se
344343
result = TryGetNextBufferResult.SuccessHaveData;
345344
break;
346345
}
346+
347+
// tell the caller that we *had* more segments (and have advanced), even if not useful
348+
result = TryGetNextBufferResult.FailureAllRemainingSegmentsEmpty;
347349
}
348350
}
349351
return result;
@@ -387,7 +389,7 @@ internal void AdvanceCurrentSpan(long count)
387389
AssertValidPosition();
388390
}
389391

390-
[MethodImpl(MethodImplOptions.NoInlining)] // avoid what looks like a JIT regression with it inlining this too much from Advance
392+
[MethodImpl(MethodImplOptions.NoInlining)] // avoid inlining this too much from Advance
391393
private void AdvanceToNextSpan(long count)
392394
{
393395
AssertValidPosition();

0 commit comments

Comments
 (0)