Skip to content

Commit

Permalink
use static where possible
Browse files Browse the repository at this point in the history
reduces stack alloc
  • Loading branch information
SimonCropp authored and Twinki14 committed Dec 30, 2023
1 parent b1395fa commit 3b31c78
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Serilog/Capturing/DepthLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DepthLimiter(int maximumDepth, PropertyValueConverter propertyValueConver
_propertyValueConverter = propertyValueConverter;
}

public void SetCurrentDepth(int depth)
public static void SetCurrentDepth(int depth)
{
_currentDepth = depth;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Serilog/Capturing/PropertyValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ LogEventPropertyValue CreatePropertyValue(object value, Destructuring destructur
}

var valueType = value.GetType();
_depthLimiter.SetCurrentDepth(depth);
DepthLimiter.SetCurrentDepth(depth);

if (destructuring == Destructuring.Destructure)
{
Expand Down Expand Up @@ -309,7 +309,7 @@ string TruncateIfNecessary(string text)
return text;
}

bool TryGetDictionary(object value, Type valueType, out IDictionary dictionary)
static bool TryGetDictionary(object value, Type valueType, out IDictionary dictionary)
{
if (valueType.IsConstructedGenericType &&
valueType.GetGenericTypeDefinition() == typeof(Dictionary<,>) &&
Expand All @@ -323,7 +323,7 @@ bool TryGetDictionary(object value, Type valueType, out IDictionary dictionary)
return false;
}

bool IsValidDictionaryKeyType(Type valueType)
static bool IsValidDictionaryKeyType(Type valueType)
{
return BuiltInScalarTypes.Contains(valueType) ||
valueType.GetTypeInfo().IsEnum;
Expand Down
2 changes: 1 addition & 1 deletion test/Serilog.Tests/LoggerConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public void MaximumCollectionCountNotEffectiveForDictionaryWithAsManyKeysAsLimit
Assert.Contains("2", limitedCollection);
}

private string LogAndGetAsString(object x, Func<LoggerConfiguration, LoggerConfiguration> conf, string destructuringSymbol = "")
private static string LogAndGetAsString(object x, Func<LoggerConfiguration, LoggerConfiguration> conf, string destructuringSymbol = "")
{
LogEvent evt = null;
var logConf = new LoggerConfiguration()
Expand Down
2 changes: 1 addition & 1 deletion test/Serilog.Tests/MethodOverloadConventionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ void ForContextMethod4(MethodInfo method)
}

// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
void TestForContextResult(MethodInfo method, ILogger logger, object normalResult)
static void TestForContextResult(MethodInfo method, ILogger logger, object normalResult)
{
Assert.NotNull(normalResult);
Assert.True(normalResult is ILogger);
Expand Down

0 comments on commit 3b31c78

Please sign in to comment.