-
Notifications
You must be signed in to change notification settings - Fork 51
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Linq; | ||
|
||
namespace SyslogNet.Client.Serialization | ||
{ | ||
|
@@ -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; | ||
if (structuredData != null && structuredData.Length != 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary change, you should leave it as Any() |
||
{ | ||
// Space | ||
stream.WriteByte(32); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SyslogNet.Client | ||
{ | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -128,7 +127,7 @@ public string Message | |
get { return message; } | ||
} | ||
|
||
public IEnumerable<StructuredDataElement> StructuredDataElements | ||
public StructuredDataElement[] StructuredDataElements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary change, you should leave it as IEnumerable |
||
{ | ||
get { return structuredDataElements; } | ||
} | ||
|
There was a problem hiding this comment.
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.