Skip to content
Merged
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 @@ -1755,6 +1755,19 @@ public TagsLinkedList(IEnumerator<KeyValuePair<string, object?>> e)
}
}

public TagsLinkedList(ReadOnlySpan<KeyValuePair<string, object?>> tags)
{
Debug.Assert(tags.Length > 0);

_last = _first = new DiagNode<KeyValuePair<string, object?>>(tags[0]);

for (int i = 1; i < tags.Length; i++)
{
_last.Next = new DiagNode<KeyValuePair<string, object?>>(tags[i]);
_last = _last.Next;
}
}

public DiagNode<KeyValuePair<string, object?>>? First => _first;

public TagsLinkedList(IEnumerable<KeyValuePair<string, object?>> list) => Add(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ public ActivityEvent(string name) : this(name, DateTimeOffset.UtcNow, tags: null
/// <param name="tags">Event Tags.</param>
public ActivityEvent(string name, DateTimeOffset timestamp = default, ActivityTagsCollection? tags = null) : this(name, timestamp, tags, tags is null ? 0 : tags.Count) { }

internal ActivityEvent(string name, DateTimeOffset timestamp, ref TagList tags) : this(name, timestamp, tags, tags.Count) { }
internal ActivityEvent(string name, DateTimeOffset timestamp, ref TagList tags)
{
Name = name ?? string.Empty;
Timestamp = timestamp != default ? timestamp : DateTimeOffset.UtcNow;

#if NET
// Read directly from the TagList's span so we avoid boxing the TagList (and its
// enumerator) as an IEnumerable<T> just to copy its tags into the linked list below.
_tags = tags.Count > 0 ? new Activity.TagsLinkedList(tags.Tags) : null;
#else
_tags = tags.Count > 0 ? new Activity.TagsLinkedList((IEnumerable<KeyValuePair<string, object?>>)tags) : null;
#endif
}

private ActivityEvent(string name, DateTimeOffset timestamp, IEnumerable<KeyValuePair<string, object?>>? tags, int tagsCount)
{
Expand Down
Loading