Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PERF] Don't split and join lines when using TextFile #644

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

TungstnBallon
Copy link
Contributor

Problem: When chaining TextRangeSelector and TextLineDeleter the following happens:

// TextRangeSelector
let lines = splitLines(file.content);
let newLines = /* ... select range ... */;
return new TextFile(newLines.join());

// ...

// TextLineDeleter
let lines = splitLines(file.content);
let newLines = /* ... deleteLines ... */;
return new TextFile(newLines.join());

This might mean a lot of "useless" splits and joins, which becomes especially problematic for large files.

Solution: Introduce the new util function findLineBounds(). This function takes a sorted array of line indices, a regex to find line breaks and the text as parameters. It maps each line index to the start of the line and its length, stopping at the first non existent line index.

I didn't remove the now unused transformTextFileLines(), because deleting working, tested code seems unnecessary, but let me know it you think otherwise.

@TungstnBallon TungstnBallon self-assigned this Jan 29, 2025
@TungstnBallon TungstnBallon merged commit 1f4dc40 into main Jan 29, 2025
3 checks passed
@TungstnBallon TungstnBallon deleted the perf-text-file branch January 29, 2025 11:34
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants