Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unnecessary copy on serialization #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;

namespace SyslogNet.Client.Serialization
{
Expand Down Expand Up @@ -33,8 +32,8 @@ public void Serialize(SyslogMessage message, Stream stream)

writeStream(stream, Encoding.ASCII, messageBuilder.ToString());

var structuredData = message.StructuredDataElements?.ToList();
if (structuredData != null && structuredData.Any())
var structuredData = message.StructuredDataElements;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ToList is indeed not necessary in this case, it should be removed to avoid a potential costly materialization.

if (structuredData != null && structuredData.Length != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change, you should leave it as Any()

{
// Space
stream.WriteByte(32);
Expand Down
5 changes: 2 additions & 3 deletions SyslogNet.Client/SyslogMessage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace SyslogNet.Client
{
Expand All @@ -12,7 +11,7 @@ public class SyslogMessage
private readonly string procId;
private readonly string msgId;
private readonly string message;
private readonly IEnumerable<StructuredDataElement> structuredDataElements;
private readonly StructuredDataElement[] structuredDataElements;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change, you should leave it as IEnumerable

private readonly DateTimeOffset? dateTimeOffset;

public static Facility DefaultFacility = Facility.UserLevelMessages;
Expand Down Expand Up @@ -128,7 +127,7 @@ public string Message
get { return message; }
}

public IEnumerable<StructuredDataElement> StructuredDataElements
public StructuredDataElement[] StructuredDataElements
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change, you should leave it as IEnumerable

{
get { return structuredDataElements; }
}
Expand Down