Skip to content

Commit

Permalink
review use of lists (#151)
Browse files Browse the repository at this point in the history
* review use of lists

* Use Enumerable.Empty

* Remove alloc of empty array
  • Loading branch information
bruno-garcia authored and austinlparker committed Jul 24, 2019
1 parent 8e1d8fa commit b02f312
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Abstractions/Trace/Export/LinkList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace OpenTelemetry.Trace.Export

public sealed class LinkList : ILinks
{
public static readonly LinkList Empty = new LinkList(new ILink[0], 0);
public static readonly LinkList Empty = new LinkList(Enumerable.Empty<ILink>(), 0);

internal LinkList(IEnumerable<ILink> links, int droppedLinksCount)
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Abstractions/Trace/Export/TimedEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ namespace OpenTelemetry.Trace.Export

public sealed class TimedEvents<T> : ITimedEvents<T>
{
public static readonly ITimedEvents<T> Empty = new TimedEvents<T>(new ITimedEvent<T>[0], 0);
public static readonly ITimedEvents<T> Empty = new TimedEvents<T>(Enumerable.Empty<ITimedEvent<T>>(), 0);

internal TimedEvents(IEnumerable<ITimedEvent<T>> events, int droppedEventsCount)
{
this.Events = events ?? throw new ArgumentNullException("Null events");
this.Events = events ?? throw new ArgumentNullException(nameof(events), "Null events");
this.DroppedEventsCount = droppedEventsCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ public static List<TimeSeries> CreateTimeSeriesList(
timeSeries.Metric = GetMetric(view, labels, metricDescriptor, domain);

var point = ExtractPointInInterval(viewData.Start, viewData.End, view.Aggregation, points);
var timeSeriesPoints = new List<Point> { point };
timeSeries.Points.AddRange(timeSeriesPoints);
timeSeries.Points.Add(point);

timeSeriesList.Add(timeSeries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal class ZipkinSpan
public ZipkinEndpoint RemoteEndpoint { get; set; }

[JsonProperty("annotations")]
public List<ZipkinAnnotation> Annotations { get; set; }
public IList<ZipkinAnnotation> Annotations { get; set; }

[JsonProperty("tags")]
public Dictionary<string, string> Tags { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Stats/MutableViewData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected MutableViewData(IView view)

private static Func<MutableDistribution, IAggregationData> CreateDistributionData { get; } = (s) =>
{
var boxedBucketCounts = new List<long>();
var boxedBucketCounts = new List<long>(s.BucketCounts.Length);
foreach (var bucketCount in s.BucketCounts)
{
boxedBucketCounts.Add(bucketCount);
Expand Down

0 comments on commit b02f312

Please sign in to comment.