Skip to content

Commit 5bec10c

Browse files
committed
FormattedLogValues - Small optimization for index operatoe
1 parent bae19aa commit 5bec10c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,21 @@ public FormattedLogValues(string? format, params object?[]? values)
6464
{
6565
get
6666
{
67-
if (index < 0 || index >= Count)
67+
if (_formatter is null || _values is null)
6868
{
69-
throw new IndexOutOfRangeException();
69+
if (index == 0)
70+
{
71+
return new KeyValuePair<string, object?>("{OriginalFormat}", _originalMessage);
72+
}
73+
else
74+
{
75+
throw new IndexOutOfRangeException();
76+
}
7077
}
71-
72-
if (index == Count - 1)
78+
else
7379
{
74-
return new KeyValuePair<string, object?>("{OriginalFormat}", _originalMessage);
80+
return _formatter.GetValue(_values, index);
7581
}
76-
77-
return _formatter!.GetValue(_values!, index);
7882
}
7983
}
8084

0 commit comments

Comments
 (0)