From c7a94b5003143b546b3da5159b0ead164f155517 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:25:44 -0500 Subject: [PATCH] Reduce allocations when writing plaintext relative chats less than 24 hours long --- TwitchDownloaderCore/Chat/ChatText.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TwitchDownloaderCore/Chat/ChatText.cs b/TwitchDownloaderCore/Chat/ChatText.cs index df09a61b..31930e81 100644 --- a/TwitchDownloaderCore/Chat/ChatText.cs +++ b/TwitchDownloaderCore/Chat/ChatText.cs @@ -39,7 +39,14 @@ public static async Task SerializeAsync(string filePath, ChatRoot chatRoot, Time else if (timeFormat == TimestampFormat.Relative) { var time = TimeSpan.FromSeconds(comment.content_offset_seconds); - await sw.WriteLineAsync(string.Create(TimeSpanHFormat.ReusableInstance, @$"[{time:H\:mm\:ss}] {username}: {message}")); + if (time.Ticks < 24 * TimeSpan.TicksPerHour) + { + await sw.WriteLineAsync(@$"[{time:h\:mm\:ss}] {username}: {message}"); + } + else + { + await sw.WriteLineAsync(string.Create(TimeSpanHFormat.ReusableInstance, @$"[{time:H\:mm\:ss}] {username}: {message}")); + } } else if (timeFormat == TimestampFormat.None) {