mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-23 05:08:34 +01:00
improve performance of TextFormatter tokenization
This commit is contained in:
parent
455ab59f09
commit
1759f0ef5b
1 changed files with 4 additions and 2 deletions
|
@ -76,9 +76,9 @@ namespace MLEM.Formatting {
|
||||||
var firstCode = this.GetNextCode(s, 0, 0);
|
var firstCode = this.GetNextCode(s, 0, 0);
|
||||||
if (firstCode != null)
|
if (firstCode != null)
|
||||||
codes.Add(firstCode);
|
codes.Add(firstCode);
|
||||||
|
var index = 0;
|
||||||
var rawIndex = 0;
|
var rawIndex = 0;
|
||||||
while (rawIndex < s.Length) {
|
while (rawIndex < s.Length) {
|
||||||
var index = StripFormatting(font, s.Substring(0, rawIndex), tokens.SelectMany(t => t.AppliedCodes)).Length;
|
|
||||||
var next = this.GetNextCode(s, rawIndex + 1);
|
var next = this.GetNextCode(s, rawIndex + 1);
|
||||||
// if we've reached the end of the string
|
// if we've reached the end of the string
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
|
@ -89,10 +89,12 @@ namespace MLEM.Formatting {
|
||||||
|
|
||||||
// create a new token for the content up to the next code
|
// create a new token for the content up to the next code
|
||||||
var ret = s.Substring(rawIndex, next.Match.Index - rawIndex);
|
var ret = s.Substring(rawIndex, next.Match.Index - rawIndex);
|
||||||
tokens.Add(new Token(codes.ToArray(), index, rawIndex, StripFormatting(font, ret, codes), ret));
|
var strippedRet = StripFormatting(font, ret, codes);
|
||||||
|
tokens.Add(new Token(codes.ToArray(), index, rawIndex, strippedRet, ret));
|
||||||
|
|
||||||
// move to the start of the next code
|
// move to the start of the next code
|
||||||
rawIndex = next.Match.Index;
|
rawIndex = next.Match.Index;
|
||||||
|
index += strippedRet.Length;
|
||||||
|
|
||||||
// remove all codes that are incompatible with the next one and apply it
|
// remove all codes that are incompatible with the next one and apply it
|
||||||
codes.RemoveAll(c => c.EndsHere(next));
|
codes.RemoveAll(c => c.EndsHere(next));
|
||||||
|
|
Loading…
Reference in a new issue