Skip to content

Small FormattedLogValues Parameter Lookup Optimization #122046

@snakefoot

Description

@snakefoot

Maybe this code:

public KeyValuePair<string, object?> this[int index]
{
get
{
if (index < 0 || index >= Count)
{
throw new IndexOutOfRangeException();
}
if (index == Count - 1)
{

Can be optimized to single Count-Lookup like this:

 public KeyValuePair<string, object?> this[int index] 
 { 
     get 
     {
         var parameterCount = Count;
         if (index < 0 || index >= parameterCount) 
         { 
             throw new IndexOutOfRangeException(); 
         } 
  
         if (index == parameterCount - 1) 

Since Count is a "complex" method:

public int Count
{
get
{
if (_formatter == null)
{
return 1;
}
return _formatter.ValueNames.Count + 1;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions