Skip to content

Commit ed98e01

Browse files
committed
simplify TryReadLine
1 parent fd22ec2 commit ed98e01

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode/NodeBase.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,15 +548,13 @@ static bool TryReadLine(ref ReadOnlySequence<byte> buffer, out ReadOnlySequence<
548548
}
549549

550550
// trim the CR just before the LF, in case the line ends with CRLF
551-
var lineLength = line.Length;
552-
553-
if (0 < lineLength) {
551+
if (1 < reader.Consumed) {
554552
var lineReader = new SequenceReader<byte>(line);
555553

556-
lineReader.Advance(lineLength - 1);
554+
lineReader.Advance(reader.Consumed - 2 /* <CR?>+<LF> */);
557555

558-
if (lineReader.UnreadSpan[0] == CR)
559-
line = line.Slice(0, lineLength - 1);
556+
if (lineReader.IsNext(CR))
557+
line = line.Slice(0, lineReader.Position); // trim CR
560558
}
561559

562560
#if SYSTEM_BUFFERS_SEQUENCEREADER_UNREADSEQUENCE

0 commit comments

Comments
 (0)