From e205c078b9fd0704e7bd778e2a214049472535df Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 7 Jun 2017 20:10:35 +1000 Subject: [PATCH] Fewer arg checks; seal message template token classes; encourage inlining --- src/Serilog/Events/MessageTemplate.cs | 2 ++ src/Serilog/Parsing/PropertyToken.cs | 2 +- src/Serilog/Parsing/TextToken.cs | 2 +- src/Serilog/Rendering/MessageTemplateRenderer.cs | 6 ++---- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Serilog/Events/MessageTemplate.cs b/src/Serilog/Events/MessageTemplate.cs index 240cee9ed..b1664aeea 100644 --- a/src/Serilog/Events/MessageTemplate.cs +++ b/src/Serilog/Events/MessageTemplate.cs @@ -158,6 +158,8 @@ public string Render(IReadOnlyDictionary properti /// Supplies culture-specific formatting information, or null. public void Render(IReadOnlyDictionary properties, TextWriter output, IFormatProvider formatProvider = null) { + if (properties == null) throw new ArgumentNullException(nameof(properties)); + if (output == null) throw new ArgumentNullException(nameof(output)); MessageTemplateRenderer.Render(this, properties, output, null, formatProvider); } } diff --git a/src/Serilog/Parsing/PropertyToken.cs b/src/Serilog/Parsing/PropertyToken.cs index 282f9b1e2..01dcc2109 100644 --- a/src/Serilog/Parsing/PropertyToken.cs +++ b/src/Serilog/Parsing/PropertyToken.cs @@ -25,7 +25,7 @@ namespace Serilog.Parsing /// /// A message template token representing a log event property. /// - public class PropertyToken : MessageTemplateToken + public sealed class PropertyToken : MessageTemplateToken { readonly string _rawText; readonly int? _position; diff --git a/src/Serilog/Parsing/TextToken.cs b/src/Serilog/Parsing/TextToken.cs index 974e5f530..493a1b56d 100644 --- a/src/Serilog/Parsing/TextToken.cs +++ b/src/Serilog/Parsing/TextToken.cs @@ -23,7 +23,7 @@ namespace Serilog.Parsing /// /// A message template token representing literal text. /// - public class TextToken : MessageTemplateToken + public sealed class TextToken : MessageTemplateToken { /// /// Construct a . diff --git a/src/Serilog/Rendering/MessageTemplateRenderer.cs b/src/Serilog/Rendering/MessageTemplateRenderer.cs index 7da313f09..090e39e98 100644 --- a/src/Serilog/Rendering/MessageTemplateRenderer.cs +++ b/src/Serilog/Rendering/MessageTemplateRenderer.cs @@ -15,6 +15,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; using Serilog.Events; using Serilog.Formatting.Json; using Serilog.Parsing; @@ -25,12 +26,9 @@ static class MessageTemplateRenderer { static JsonValueFormatter JsonValueFormatter = new JsonValueFormatter("$type"); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Render(MessageTemplate messageTemplate, IReadOnlyDictionary properties, TextWriter output, string format = null, IFormatProvider formatProvider = null) { - if (messageTemplate == null) throw new ArgumentNullException(nameof(messageTemplate)); - if (properties == null) throw new ArgumentNullException(nameof(properties)); - if (output == null) throw new ArgumentNullException(nameof(output)); - bool isLiteral = false, isJson = false; if (format != null)