Browse Source

Remove generic methods from ILogSink.

Part of the push to remove generic virtual methods from Avalonia for performance reasons.

Generic methods were added to this interface in #3055 to prevent boxing before we added `Logger.TryGet` (#4135).

Given that since we added `Logger.TryGet`, only enabled logging levels will result in a call to the logger, we can move back to using `params object[]` and boxing; removing the generic interface methods.
Steven Kirk 3 years ago
parent
commit
c34b7f2d31

+ 0 - 51
src/Avalonia.Base/Logging/ILogSink.cs

@@ -26,57 +26,6 @@ namespace Avalonia.Logging
             object? source,
             string messageTemplate);
 
-        /// <summary>
-        /// Logs an event.
-        /// </summary>
-        /// <param name="level">The log event level.</param>
-        /// <param name="area">The area that the event originates.</param>
-        /// <param name="source">The object from which the event originates.</param>
-        /// <param name="messageTemplate">The message template.</param>
-        /// <param name="propertyValue0">Message property value.</param>
-        void Log<T0>(
-            LogEventLevel level,
-            string area,
-            object? source,
-            string messageTemplate,
-            T0 propertyValue0);
-
-        /// <summary>
-        /// Logs an event.
-        /// </summary>
-        /// <param name="level">The log event level.</param>
-        /// <param name="area">The area that the event originates.</param>
-        /// <param name="source">The object from which the event originates.</param>
-        /// <param name="messageTemplate">The message template.</param>
-        /// <param name="propertyValue0">Message property value.</param>
-        /// <param name="propertyValue1">Message property value.</param>
-        void Log<T0, T1>(
-            LogEventLevel level,
-            string area,
-            object? source,
-            string messageTemplate,
-            T0 propertyValue0,
-            T1 propertyValue1);
-
-        /// <summary>
-        /// Logs an event.
-        /// </summary>
-        /// <param name="level">The log event level.</param>
-        /// <param name="area">The area that the event originates.</param>
-        /// <param name="source">The object from which the event originates.</param>
-        /// <param name="messageTemplate">The message template.</param>
-        /// <param name="propertyValue0">Message property value.</param>
-        /// <param name="propertyValue1">Message property value.</param>
-        /// <param name="propertyValue2">Message property value.</param>
-        void Log<T0, T1, T2>(
-            LogEventLevel level,
-            string area,
-            object? source,
-            string messageTemplate,
-            T0 propertyValue0,
-            T1 propertyValue1,
-            T2 propertyValue2);
-
         /// <summary>
         /// Logs a new event.
         /// </summary>

+ 3 - 35
src/Avalonia.Base/Logging/TraceLogSink.cs

@@ -28,31 +28,7 @@ namespace Avalonia.Logging
         {
             if (IsEnabled(level, area))
             {
-                Trace.WriteLine(Format<object, object, object>(area, messageTemplate, source));
-            }
-        }
-
-        public void Log<T0>(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0)
-        {
-            if (IsEnabled(level, area))
-            {
-                Trace.WriteLine(Format<T0, object, object>(area, messageTemplate, source, propertyValue0));
-            }
-        }
-
-        public void Log<T0, T1>(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
-        {
-            if (IsEnabled(level, area))
-            {
-                Trace.WriteLine(Format<T0, T1, object>(area, messageTemplate, source, propertyValue0, propertyValue1));
-            }
-        }
-
-        public void Log<T0, T1, T2>(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
-        {
-            if (IsEnabled(level, area))
-            {
-                Trace.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1, propertyValue2));
+                Trace.WriteLine(Format<object, object, object>(area, messageTemplate, source, null));
             }
         }
 
@@ -68,9 +44,7 @@ namespace Avalonia.Logging
             string area,
             string template,
             object? source,
-            T0? v0 = default,
-            T1? v1 = default,
-            T2? v2 = default)
+            object?[]? values)
         {
             var result = new StringBuilder(template.Length);
             var r = new CharacterReader(template.AsSpan());
@@ -93,13 +67,7 @@ namespace Avalonia.Logging
                     if (r.Peek != '{')
                     {
                         result.Append('\'');
-                        result.Append(i++ switch
-                        {
-                            0 => v0,
-                            1 => v1,
-                            2 => v2,
-                            _ => null
-                        });
+                        result.Append(values?[i++]);
                         result.Append('\'');
                         r.TakeUntil('}');
                         r.Take();

+ 0 - 17
tests/Avalonia.UnitTests/TestLogSink.cs

@@ -37,23 +37,6 @@ namespace Avalonia.UnitTests
             _callback(level, area, source, messageTemplate);
         }
 
-        public void Log<T0>(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0)
-        {
-            _callback(level, area, source, messageTemplate, propertyValue0);
-        }
-
-        public void Log<T0, T1>(LogEventLevel level, string area, object source, string messageTemplate,
-            T0 propertyValue0, T1 propertyValue1)
-        {
-            _callback(level, area, source, messageTemplate, propertyValue0, propertyValue1);
-        }
-
-        public void Log<T0, T1, T2>(LogEventLevel level, string area, object source, string messageTemplate,
-            T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
-        {
-            _callback(level, area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
-        }
-
         public void Log(LogEventLevel level, string area, object source, string messageTemplate,
             params object[] propertyValues)
         {