Stepami / hydrascript

TypeScript & Go inspired open-source public research project written in C#
GNU General Public License v3.0
70 stars 4 forks source link

[feature request] Оптимизировать алгоритм Поиска Новых строк #107

Closed Stepami closed 2 months ago

Stepami commented 2 months ago

Is your feature request related to a problem? Please describe. Текущая реализация использует LinkedList и регулярные выделения Span'ов, что неоптимально https://github.com/Stepami/hydrascript/blob/master/src/Domain/HydraScript.Domain.FrontEnd/Lexer/Impl/TextCoordinateSystemComputer.cs

Describe the solution you'd like

var indices = new List<int>(capacity: 128) { -1 };
var textAsSpan = LoremIpsum.AsSpan();
while (true)
{
    var start = indices[^1] + 1;
    if (start == _loremIpsumLength)
        break;
    var index = textAsSpan.Slice(
            start,
            length: _loremIpsumLength - start)
        .IndexOfAny(_sv);
    indices.Add(start + index);
}