Skip to content

Commit

Permalink
load/save optimize: replace slow RemoveAt() call with smarter LINQ
Browse files Browse the repository at this point in the history
- should save about 3 seconds on loading projects
  • Loading branch information
binary1230 committed Jan 24, 2024
1 parent b0279c6 commit 71a6af9
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions Diz.Core/serialization/xml_serializer/RomBytesXMLSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,10 @@ private static List<string> ReadMainDataRaw(string allLines)
if (encodedWithCompressGroupBlocks)
RepeaterCompression.Decompress(ref lines);

// remove comments and extra whitespace (comments start with ";" and extend to the rest of the line)
for (var i = 0; i < lines.Count; i++)
{
// remove any comments (semicolon) from lines
var indexSemiColon = lines[i].IndexOf(';');
if (indexSemiColon != -1) {
lines[i] = lines[i][..indexSemiColon].TrimEnd();
}

// after that, remove any blank lines (this removes lines where it was ONLY a comment, and there's nothing else on it)
// this is also important for merging/etc to cull lines with just whitespace.
if (string.IsNullOrWhiteSpace(lines[i]))
lines.RemoveAt(i--);
}

return lines;
return lines
.Select(line => line.Contains(';') ? line[..line.IndexOf(';')].TrimEnd() : line) // remove any comments
.Where(line => !string.IsNullOrWhiteSpace(line)) // remove any blank lines (including newly blanked lines because they used to have a comment in them)
.ToList();
}

private static (List<string> lines, List<string> options) ReadHeader(string allLines)
Expand Down

0 comments on commit 71a6af9

Please sign in to comment.