From 538fd08d8a730da725c13f51b0aadcd84953864b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 14 Apr 2021 02:47:41 +0200 Subject: [PATCH] improved TokenizedString splitting efficiency --- MLEM/Formatting/TokenizedString.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MLEM/Formatting/TokenizedString.cs b/MLEM/Formatting/TokenizedString.cs index 6499d49..6c70d5f 100644 --- a/MLEM/Formatting/TokenizedString.cs +++ b/MLEM/Formatting/TokenizedString.cs @@ -68,9 +68,9 @@ namespace MLEM.Formatting { 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; i++) { + 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 && length < token.Substring.Length) + if (index >= token.Index) ret.Append(this.splitString[i]); // if the current char is not a newline, we simulate length increase if (this.splitString[i] != '\n') {