Skip to content

Commit

Permalink
reduce allocations on newline
Browse files Browse the repository at this point in the history
  • Loading branch information
j0nimost committed Oct 26, 2023
1 parent fd0cfc9 commit 4a2cacc
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/Kafa/Writer/KafaWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal class KafaWriter : IDisposable
private IBufferWriter<byte>? _bufferWriter;
private KafaPooledWriter? _kafaPooledWriter;
private Stream? _stream = default;
private readonly byte[] _unixNewLine =new byte[1] {(byte)'\n'};
private readonly byte[] _winNewLine = new byte[2] {(byte)'\r',(byte)'\n'};

private readonly KafaOptions _options;

Expand All @@ -34,25 +36,9 @@ public void WriteSeparator()

public void WriteLine()
{
byte[] newLine;
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
newLine = new byte[1]
{
(byte)'\n'
};
}
else
{
newLine = new byte[2]
{
(byte)'\r',
(byte)'\n'
};
}
var newLine = Environment.OSVersion.Platform == PlatformID.Unix ? _unixNewLine : _winNewLine;

Write(newLine);

}

public void Write(string str)
Expand Down

0 comments on commit 4a2cacc

Please sign in to comment.