1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-19 15:41:22 +02: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;
return;
}
foreach (var token in this.Tokens) {
var index = 0;
var length = 0;
var ret = new StringBuilder();
// this is basically a substring function that ignores newlines for indexing
for (var i = 0; i < this.splitString.Length && length < token.Substring.Length; i++) {
// if we're within the bounds of the token's substring, append to the new substring
if (index >= token.Index)
ret.Append(this.splitString[i]);
// this is basically a substring function that ignores newlines for indexing
var index = 0;
var currToken = 0;
var splitIndex = 0;
var ret = new StringBuilder();
while (splitIndex < this.splitString.Length) {
var token = this.Tokens[currToken];
if (token.Substring.Length > 0) {
ret.Append(this.splitString[splitIndex]);
// if the current char is not an added newline, we simulate length increase
if (this.splitString[i] != '\n' || this.String[index] == '\n') {
if (index >= token.Index)
length++;
if (this.splitString[splitIndex] != '\n' || this.String[index] == '\n')
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);
}