1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

improved performance of TokenizedString splitting massively

This commit is contained in:
Ell 2021-04-22 01:14:48 +02:00
parent 60bc320604
commit 455ab59f09

View file

@ -64,24 +64,29 @@ namespace MLEM.Formatting {
this.Tokens[0].SplitSubstring = this.splitString; this.Tokens[0].SplitSubstring = this.splitString;
return; return;
} }
foreach (var token in this.Tokens) {
var index = 0; // this is basically a substring function that ignores newlines for indexing
var length = 0; var index = 0;
var ret = new StringBuilder(); var currToken = 0;
// this is basically a substring function that ignores newlines for indexing var splitIndex = 0;
for (var i = 0; i < this.splitString.Length && length < token.Substring.Length; i++) { var ret = new StringBuilder();
// if we're within the bounds of the token's substring, append to the new substring while (splitIndex < this.splitString.Length) {
if (index >= token.Index) var token = this.Tokens[currToken];
ret.Append(this.splitString[i]); if (token.Substring.Length > 0) {
ret.Append(this.splitString[splitIndex]);
// if the current char is not an added newline, we simulate length increase // if the current char is not an added newline, we simulate length increase
if (this.splitString[i] != '\n' || this.String[index] == '\n') { if (this.splitString[splitIndex] != '\n' || this.String[index] == '\n')
if (index >= token.Index)
length++;
index++; index++;
} splitIndex++;
}
// move on to the next token if we reached its end
if (index >= token.Index + token.Substring.Length) {
token.SplitSubstring = ret.ToString();
ret.Clear();
currToken++;
} }
token.SplitSubstring = ret.ToString();
} }
this.CalculateTokenAreas(font); this.CalculateTokenAreas(font);
} }