optimise splitting code for short logs

This commit is contained in:
Florian Stinglmayr 2024-09-17 19:54:35 +02:00
parent 20adf93d39
commit 8eaf94f634
2 changed files with 10 additions and 1 deletions

View File

@ -207,7 +207,11 @@ public class DiscordLogGenerator {
string[] lines = log.Split("\n"); string[] lines = log.Split("\n");
List<string> chunks = new(); List<string> chunks = new();
string chunk = string.Empty; string chunk = string.Empty;
bool done = false;
// Optimisation
if (log.Length <= maxcount) {
return new string[] { log };
}
// First split the log into its headers // First split the log into its headers
// skip first bot header line // skip first bot header line

View File

@ -33,6 +33,11 @@ public class OneLineDiscordLog : DiscordLogGenerator {
List<string> chunks = new(); List<string> chunks = new();
string chunk = string.Empty; string chunk = string.Empty;
// Optimisation
if (log.Length <= maxcount) {
return new string[] { log };
}
for (int i = 0; i < lines.Length; i++) { for (int i = 0; i < lines.Length; i++) {
string line = lines[i]; string line = lines[i];
if ((chunk.Length + line.Length) > maxcount || i == lines.Length - 1) { if ((chunk.Length + line.Length) > maxcount || i == lines.Length - 1) {