mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-23 05:08:34 +01:00
improved performance of TokenizedString splitting massively
This commit is contained in:
parent
60bc320604
commit
455ab59f09
1 changed files with 19 additions and 14 deletions
|
@ -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;
|
|
||||||
var length = 0;
|
|
||||||
var ret = new StringBuilder();
|
|
||||||
// this is basically a substring function that ignores newlines for indexing
|
// this is basically a substring function that ignores newlines for indexing
|
||||||
for (var i = 0; i < this.splitString.Length && length < token.Substring.Length; i++) {
|
var index = 0;
|
||||||
// if we're within the bounds of the token's substring, append to the new substring
|
var currToken = 0;
|
||||||
if (index >= token.Index)
|
var splitIndex = 0;
|
||||||
ret.Append(this.splitString[i]);
|
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 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();
|
token.SplitSubstring = ret.ToString();
|
||||||
|
ret.Clear();
|
||||||
|
currToken++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.CalculateTokenAreas(font);
|
this.CalculateTokenAreas(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue