Skip to content

Commit 47922b2

Browse files
Construct hint items lazily (avoid unnecessary allocations when not used) (#2632)
1 parent 4feb44e commit 47922b2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Sentry/Hint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Hint
88
{
99
private readonly SentryOptions? _options;
1010
private readonly List<Attachment> _attachments = new();
11-
private readonly Dictionary<string, object?> _items = new();
11+
private Dictionary<string, object?>? _items;
1212

1313
/// <summary>
1414
/// Creates a new instance of <see cref="Hint"/>.
@@ -30,7 +30,7 @@ internal Hint(SentryOptions? options)
3030
public Hint(string key, object? value)
3131
: this()
3232
{
33-
_items[key] = value;
33+
Items[key] = value;
3434
}
3535

3636
/// <summary>
@@ -49,7 +49,7 @@ public Hint(string key, object? value)
4949
/// These are not sent to Sentry, but rather they are available during processing, such as when using
5050
/// BeforeSend and others.
5151
/// </remarks>
52-
public IDictionary<string, object?> Items => _items;
52+
public IDictionary<string, object?> Items => _items ??= new Dictionary<string, object?>();
5353

5454
/// <summary>
5555
/// The Java SDK has some logic so that certain Hint types do not copy attachments from the Scope.

0 commit comments

Comments
 (0)