Skip to content

Commit

Permalink
Reduce allocations when writing plaintext relative chats less than 24…
Browse files Browse the repository at this point in the history
… hours long (#921)
  • Loading branch information
ScrubN authored Dec 30, 2023
1 parent a985078 commit 83d5419
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion TwitchDownloaderCore/Chat/ChatText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 83d5419

Please sign in to comment.